Sign in to follow this  
quarnster

Issue with gcc 4.7 and std::strings operator==

Recommended Posts

When compiling using gcc 4.7,[code]r = engine->RegisterObjectMethod("string", "bool opEquals(const string &in) const", asFUNCTIONPR(operator==, (const string &, const string &), bool), asCALL_CDECL_OBJFIRST);[/code]
fails to compile.

GCC 4.7 has two operator== for basic_string and it doesn't know which one to use in that instance:
[code] template<typename _CharT, typename _Traits, typename _Alloc>
inline bool
operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
const basic_string<_CharT, _Traits, _Alloc>& __rhs)
{ return __lhs.compare(__rhs) == 0; }

template<typename _CharT>
inline
typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value, bool>::__type
operator==(const basic_string<_CharT>& __lhs,
const basic_string<_CharT>& __rhs)
{ return (__lhs.size() == __rhs.size()
&& !std::char_traits<_CharT>::compare(__lhs.data(), __rhs.data(),
__lhs.size())); }
[/code]

I couldn't figure out how to properly fix it so just commented out the second operator==.

Share this post


Link to post
Share on other sites
I'm not so sure I agree ;), but here it is:
[code]angelscript/sdk/add_on/scriptstdstring/scriptstdstring.cpp:518:86: error: invalid static_cast from type ‘<unresolved overloaded function type>’ to type ‘bool (*)(const string&, const string&) {aka bool (*)(const std::basic_string<char>&, const std::basic_string<char>&)}’[/code]

Share this post


Link to post
Share on other sites
I would advise strong caution when using GCC 4.7.0 or GCC 4.7.1. The C++ standard library bundled with those version has a seriously broken ABI, particularly with respect to std::list and std::string. I suggest you stick to GCC 4.6 or GCC 4.7.2 or later.

Share this post


Link to post
Share on other sites
[quote name='Bregma' timestamp='1343305082' post='4963272']
I would advise strong caution when using GCC 4.7.0 or GCC 4.7.1. The C++ standard library bundled with those version has a seriously broken ABI, particularly with respect to std::list and std::string. I suggest you stick to GCC 4.6 or GCC 4.7.2 or later.
[/quote]

i agree 4.7 has some standard library problems.
one that hurt me the most, unordered_map insert is in 4.7 is slower than std::map insert.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this