I am looking for some command-line flags (should they exist) that disable the GCC error for this type of C++ code:
#include <string>
void m(std::string& s) { }
int main()
{
m(std::string(""));
}
G++ gives this error:
error: invalid initialization of non-const reference of type ‘std::string&’ from a temporary of type ‘std::string’
The reason is to be able to quickly migrate from VC++ and Sun Studio (without any code changes), since both silently accept temporary to non-const lvalue ref conversions. I know what needs to be done in terms of code changes — I am strictly asking about a way to do it without making code changes.
I will be using GCC 4.x.
It is not conforming to the standard & there is no way to disable this through flags in GCC.
Vc++ wrongly supports this through an non-standard extension. Try with
/Za(disable language extension) flag, and you should see the errors.Or use can the
/W4flag to get maximum warnings, and it will show you:warning C4239: nonstandard extension used