I know there are topics that are similar to this one already (such as this).
The example given in this topic was this:
std::string & rs1 = std::string();
Clearly, that std::string() is an rvalue. However, my question is why is s1 legal while s2 is not?
const std::string& s1 = "String literal";
std::string& s2 = "String literal";
The standard clearly states that string literals are lvalues (which is understandable since they are technically const char* behind the scenes). When I compile s2 though, I get the following:
prog.cpp:4:19: error: invalid initialization of non-const reference of type
'std::string& {aka std::basic_string<char>&}' from an rvalue of type
'const char*' std::string& s2 = "String literal";
I understand that the standard definition of lvalues and rvalues are mutually exclusive, so is this potentially an error with the compiler? I'm using gcc 4.9.2 in this example. Would this also be one of the cases where the literal is really an xvalue?