Jump to content
  • Advertisement
Sign in to follow this  
quarnster

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

This topic is 2250 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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==.

Share this post


Link to post
Share on other sites
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>&)}’

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

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!