C++11, `noexcept` specifier, definition versus declaration
Asked Answered
G

1

23

If a declared function has a noexcept specificator (noexcept, noexcept(true), noexcept(false), or any other noexcept(expr) which evaluates to true or false), but it's defined in another place, do I need to specify the noexcept specifier in the definition again, or only in its forward declaration?

Gon answered 21/4, 2015 at 15:7 Comment(0)
L
23

[except.spec]/p4:

If any declaration of a function has an exception-specification that is not a noexcept-specification allowing all exceptions, all declarations, including the definition and any explicit specialization, of that function shall have a compatible exception-specification.

noexcept(some-constant-expression-that-evaluates-to-false) may be omitted. Anything else must be present in all declarations.

Liberec answered 21/4, 2015 at 15:31 Comment(1)
to be sure, noexcept(false) in declaration doesn't have to be present in definition ? What about inheritance and virtual stuff ?Lemuelah

© 2022 - 2024 — McMap. All rights reserved.