4 ms·
C++ has a lot of these silly rules. For the case of reserved identifiers, they are reserved for the implementation of the standard library, but of course C++ us
by Kranar 5y ago
C++ has a lot of these silly rules. For the case of reserved identifiers, they are reserved for the implementation of the standard library, but of course C++ uses a copy and paste system of #include's which takes place in the preprocessing phase, before the actual parsing/compiling phase. That means when you #include <vector> into your own main.cpp, you're copying and pasting "vector" into "main.cpp" and compiling "main.cpp", so the compiler would have to jump through all kinds of hoops to figure out that a certain section of "main.cpp" comes from "vector" and another section comes from this or that.
It's certainly possible to do this in principle, but the standard does not impose that burden on any implementation.
At any rate, the standard is full of this kind of compile time "undefined behavior". The formal term for this is "ill-formed, no diagnostic required" aka "NDR" which means that the program is invalid C++ but the compiler is not required to report an error, and running the subsequent translation is undefined behavior.