Advertisement

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

Started by July 26, 2012 10:00 AM
4 comments, last by WitchLord 12 years, 4 months ago
When compiling using gcc 4.7,r = engine->RegisterObjectMethod("string", "bool opEquals(const string &in) const", asFUNCTIONPR(operator==, (const string &, const string &), bool), asCALL_CDECL_OBJFIRST);
fails to compile.

GCC 4.7 has two operator== for basic_string and it doesn't know which one to use in that instance:
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())); }


I couldn't figure out how to properly fix it so just commented out the second operator==.
Would be great to see the compiler message
Advertisement
I'm not so sure I agree ;), but here it is:
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>&)}’
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.

Stephen M. Webb
Professional Free Software Developer


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.


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.
I imagine the solution in this case is to use the std::basic_string<char> to identify which of the two operators you want rather than std::string.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement