My collegue just ran our codebase through a new compiler for a new platform, and unsurprisingly there were errors that had not been reported before.
One of them concerned code where the original author had accidentally typed a class name twice when calling a static function of that class. The looked like this:
class Thing
{
public:
static void DoStuff ();
};
int main (int, char **)
{
Thing::Thing::DoStuff();
// or even: Thing::Thing::Thing::Thing::Thing::Thing::DoStuff();
return 0;
}
GCC 4.9.2 on my local (Cygwin) machine compiles it fine, even with -Wall -Wextra -Wpedantic
. A customized Clang that we're using for an embedded system also accepts it. Visual Studio 2012 (v110) gives me the error:
error C3083: '{ctor}': the symbol to the left of a '::' must be a type
I can imagine equally convincing arguments for:
- It's legal and the compiler accepts it. (i.e. GCC and Clang are correct, VS is wrong)
- It's not legal, but the compiler may accept it anyway.
- It's legal but the compiler doesn't accept it. (i.e. VS is wrong; maybe it's a new C++11 thing that hasn't been added yet?)
- It's not legal and the compiler shouldn't accept it. (i.e. Visual Studio is the only correct one)
- Just fix the error and get on with my life.
Which one is correct?