Program being compiled differently in 3 major C++ compilers. Which one is right?

后端 未结 2 437
北海茫月
北海茫月 2020-12-04 17:10

As an interesting follow-up (not of big practical importance though) to my previous question: Why does C++ allow us to surround the variable name in parentheses when declari

2条回答
  •  感情败类
    2020-12-04 17:47

    G++ is correct as it gives an error. Because the constructor could not be called directly in such a format without new operator. And although your code calls C::C, it looks like an constructor call. However, according to the C++11 standard 3.4.3.1, this is not a legal function call, or a type name (see Mike Seymour's answer).

    Clang is wrong since it even does not call the correct function.

    MSVC is something reasonable, but still it does not follow the standard.

提交回复
热议问题