Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trailing return-type syntax fails with noexcept specifier?

Tags:

c++

c++11

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?

like image 940
David G Avatar asked May 16 '13 22:05

David G


1 Answers

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.

like image 82
Andy Prowl Avatar answered Oct 24 '22 10:10

Andy Prowl