Is it legal (accidentally) to specify a class name twice when calling a static function?

My college just launched our codebase through a new compiler for the new platform, and it is not surprising that there were errors that were not previously reported.

One of them concerns code in which the original author accidentally typed the class name twice when calling the static function of this class. It 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 computer (Cygwin) compiles it perfectly, even with -Wall -Wextra -Wpedantic. The supported Clang, which we use for the embedded system, also accepts it. Visual Studio 2012 (v110) gives me an error:

error C3083: '{ctor}': the symbol to the left of a '::' must be a type

I can present equally convincing arguments for:

  • This is legal, and the compiler accepts it. (i.e. GCC and Clang are correct, VS is wrong)
  • , .
  • , . (.. VS , , ++ 11, ?)
  • , . (.. Visual Studio )
  • .

?

+4

Source: https://habr.com/ru/post/1608026/


All Articles