This code work as expected:
void f() noexcept {}
But the following fails with an error in GCC 4.7.2:
auto f() -> void noexcept {}
// error: expected initializer before ‘noexcept’
Articles I've read haven't said anything about not being able to specify noexcept
in a training return-type. Is this a bug (and had it been fixed in the newest version of GCC)? Or is this prohibited explicitly by the Standard?
That is not the correct syntax. It should be:
auto f() noexcept -> void { }
Per paragraph 8.4.1/2 of the C++11 Standard:
D1
( parameter-declaration-clause ) cv-qualifier-seq(opt)ref-qualifier(opt) *exception-specification(opt)* attribute-specifier-seq(opt) *trailing-return-type(opt)*
as described in 8.3.5. A function shall be defined only in namespace or class scope.
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