Yes, this is a compiler error. Function pointers must have compatible exception specifiers.
Quote from the standard:
15.4 Exception specifications
(5) ... A similar restriction applies to the assignment and initialization of function pointers, member function pointers, and function references: the target object allows at least the exceptions allowed by the original value in assignment or initialization.
Example:
class A; void (*pf1)();
Your code compiled with Comeau gives an incompatible exception specifications error:
Comeau C/C++ 4.3.10.1 (Oct 6 2008 11:28:09) for ONLINE_EVALUATION_BETA2 Copyright 1988-2008 Comeau Computing. All rights reserved. MODE:strict errors C++ C++0x_extensions "ComeauTest.c", line 9: error: incompatible exception specifications pf=foo;
Like many of the other exceptions mentioned, exception specifications are deprecated in the C ++ 11 standard (see Appendix D.4), with the exception of the noexcept specification. So the best practice (and was) is to avoid use .
source share