I think its compiler magic thats making it work. I agree with you that this ideally should be a compiler error (atleast confuses me).
If you try something like
#include <iostream>
class Test { public: int member; };
Test Test; // comaeu warns 'expression has no effect!'
Test.member = 10; // dosen't compile!
int main(){
Test Test;
Test.member = 10; // compiles fine after global 'Test's are commented!!
std::cout<<Test.member<<std::endl;
return 0;
}
The use of 'Test.member' at global scope will not compile, but the same works inside 'main()' after both the global 'Test's are commented.
C++ has enough complexities to excite programmers, how about compilers too contributing :-) ?