A noexcept-expression is a kind of exception specification: a suffix to a function declaration that represents a set of types that might be matched by an exception handler for any exception that exits a function.
The noexcept operator performs a compile-time check that returns true if an expression is declared to not throw any exceptions. It can be used within a function template's noexcept specifier to declare that the function will throw exceptions for some types but not others.
Explicit instantiations may use the noexcept specifier, but it is not required. If used, the exception specification must be the same as for all other declarations.
An implicit declaration of a destructor is considered to be noexcept(true) according to [except. spec], paragraph 14. As such, destructors must not be declared noexcept(false) but may instead rely on the implicit noexcept(true) or declare noexcept explicitly.
Consider:
class test {
private:
int n;
int impl () const noexcept {
return n;
}
public:
test () = delete;
test (int n) noexcept : n(n) { }
int get () const noexcept(noexcept(impl())) {
return impl();
}
};
GCC says no:
test.cpp:27:43: error: cannot call member function 'int test::impl() const' with
out object
int get () const noexcept(noexcept(impl())) {
Similarly:
test.cpp:27:38: error: invalid use of 'this' at top level
int get () const noexcept(noexcept(this->impl())) {
and
test.cpp:31:58: error: invalid use of incomplete type 'class test'
int get () const noexcept(noexcept(std::declval<test>().impl())) {
^
test.cpp:8:7: error: forward declaration of 'class test'
class test {
Is this intended behaviour as per the standard, or a bug in GCC (4.8.0)?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With