Below is some code where the compilers partially detect mismatch between the method declaration (i.e. with 'noexcept' specifier) and the method implementation.
The compilers report a warning for the method "bazExcept()" but fail to report anything for "baz()". But, I'm expecting warning in both cases because "bazSub()" may throw exception & "baz()" explicitly states to not throw exception.
Is that a work in progress (i.e. later compiler versions will trap that case) or something I misunderstood with 'noexcept' usage?
// Tested with C++11 & C++17
// Tested with msvc 19, gcc 9 & clang 9
// Tested using https://godbolt.org/
// Specifier 'noexcept(false)' (same as no specifier) i.e. may throw exceptions.
void bar() noexcept(false) {}
// No specifier 'noexcept' means 'noexcept(false)' i.e. may throw exceptions.
void bazSub() { throw 42; }
// Specifier 'noexcept' means 'noexcept(true)' i.e. do not throw exceptions.
// Note: Compilers do not detect the problem i.e. bazSub may throw exception.
void baz() noexcept { bazSub(); }
// Specifier 'noexcept' means 'noexcept(true)' i.e. must not throw exceptions.
// Note: Compilers generate a warning.
void bazExcept() noexcept { throw 42; }
int main() {return 1;}
Thanks for your help.