I was refactoring a term which appeared a bazilion times when by accident I produced a situation like in the code below:
#include "stdafx.h"
#include <iostream>
int foo = foo;
//By replacing with the following instruction we causes a compile error
//int foo(foo);
int _tmain(int argc, _TCHAR* argv[])
{
int bar = bar;
std::cout << "Well this is awkward " << foo << std::endl;
return 0;
}
With different debug and release configurations the compiler is silent about int foo = foo;
.
I fail to see a situation where this statement is not a bug waiting to happen. Shouldn't the Visual Studio compiler fire a warning?
I am not pretending this is an undefined behavior. I am saying that by default making an assignment from a variable to itself is likely to be the programmer mistake. Unless someone has a weird scheme around the use of the assignment operator.