This program ``` void func(){} int main() { void(*pFn)() noexcept(true); pFn = func; (void)pFn; } ``` is accepted by GCC in C++14 mode (but not by Clang), demo: https://gcc.godbolt.org/z/a3EjxcKvz Starting from C++17, GCC also rejects it. Could you please verify C++14 mode here? Related discussion: https://stackoverflow.com/q/66574353/7325599
The relevant rule before C++17 is [except.spec] p5 "A similar restriction applies to assignment to and initialization of pointers to functions, pointers to member functions, and references to functions: the target entity shall allow at least the exceptions allowed by the source value in the assignment or initialization."
G++ does not give an error for the example in p5: class A { /* ... */ }; void (*pf1)(); // no exception specification void (*pf2)() throw(A); void f() { pf1 = pf2; // OK: pf1 is less restrictive pf2 = pf1; // error: pf2 is more restrictive } That should be ill-formed in C++98/11/14. The equivalent with a noexcept-specifier would be: class A { /* ... */ }; void (*pf1)(); // no exception specification void (*pf2)() noexcept; void f() { pf1 = pf2; // OK: pf1 is less restrictive pf2 = pf1; // error: pf2 is more restrictive } G++ doesn't reject this in 98/11/14, only C++17 and up.
(In reply to Jonathan Wakely from comment #2) > G++ does not give an error for the example in p5: > > class A { /* ... */ }; > void (*pf1)(); // no exception specification > void (*pf2)() throw(A); > > void f() { > pf1 = pf2; // OK: pf1 is less restrictive > pf2 = pf1; // error: pf2 is more restrictive > } > > That should be ill-formed in C++98/11/14. The above testcase is PR 12255.
Ah yes, and I think this is a dup of pr 49332
Dup of bug 49332. *** This bug has been marked as a duplicate of bug 49332 ***