Consinder the following example:
#include <iostream>
#include <string>
struct foo { std::string value; };
inline foo bar() { return { "42" }; }
std::string my_func() {
auto &x = bar();
^^^^^^^^^^^^^^^^
return x.value;
}
int main() {
std::cout << my_func() << std::endl;
}
Compiling it both GCC and CLANG emit, most probably rightfully, the same error:
error: invalid initialization of non-const reference of type 'foo&' from an rvalue of type 'foo'
However, to my surprise it compiles and runs fine in VC++2015.
- Is this a bug of VC++2015?
- Does the standard dictates that
auto
can add implicitlyconst
ness to an object when a statement renders the program ill-formed?