I have the following code
string three()
{
return \"three\";
}
void mutate(string& ref)
{
}
int main()
{
mutate(three());
return 0;
}
I guess it depends on the compiler. g++ 4.1.2 gives me this.
In function 'int main()':
Line 15: error: invalid initialization of non-const reference of type 'std::string&' from a temporary of type 'std::string'
compilation terminated due to -Wfatal-errors.
Maybe because you're not doing anything the call is optimized away.