I am learning C++ using the books listed here. I wrote the following example(for purely academic reasons) that compiles with GCC but not with Clang and MSVC. Demo.
struct C {
static bool f() noexcept(!noexcept(C::f()))
{
return true;
}
};
As we can see here the above example compiles with gcc but not with msvc and clang.
So my question is which compiler is right here(if any).
GCC compiles this.
MSVC says:
<source>(2): fatal error C1202: recursive type or function dependency context too complex
Clang says:
<source>:2:40: error: exception specification is not available until end of class definition
static bool f() noexcept(!noexcept(C::f()))
MSVC <source>(6): fatal error C1202: recursive type or function dependency context too complex
- I think this is self explanatory. That gcc compiles this means it can predict the future. +1 for compiler differences. – CheckerbloomC::f()
is noexcept only whenC::f()
is not noexcept. – Moussenoexcept
expression uses a function currently being defined, the answer is alwaystrue
)." What would you do with that information? Being able to point at a line in the standard that give a nonsense code some behavior doesn't make the code any better. It's code that nobody should ever write. What does it matter if the standard might somehow define it? – Chavarriaf
has. – Checkerbloom