Due to some accidental copy-paste, I ran into an interesting one liner that raises a lot of questions.
#include <string>
const std::string MY_STR{MY_STR + " hello"};
This compiles on gcc, clang, msvc both on x86 and ARM platforms, and after some digging it's just utilizing an uninitialized value for instantiation. But then I observed:
#include <string>
const std::string MY_STR{MY_STR.c_str()};
This I feel should fail to compile as I am trying to use MY_STR
as an instance to retrieve the c_str()
pointer.
What in the C++ standard, if anything, makes this legal?