I had a case where, due to an error in refactoring, a colleague introduced a bug similar to this code:
using namespace std;
int main()
{
std::string s = s; // using s to initialize itself is fine?
std::cout << s << std::endl;
return 0;
}
The code compiles fine and only generates a warning in clang. The commented line should be equivalent to calling the constructor string::string(s)
for s
with an object whose constructor is not yet called. What's the use of this, why is it allowed by the language?