Bug 54849 - Override specifier with trailing return type
Summary: Override specifier with trailing return type
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.7.2
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Depends on:
Reported: 2012-10-07 17:42 UTC by Ashish Sadanandan
Modified: 2012-10-07 18:09 UTC (History)
2 users (show)

See Also:
Known to work: 4.8.0
Known to fail:
Last reconfirmed:


Note You need to log in before you can comment on or make changes to this bug.
Description Ashish Sadanandan 2012-10-07 17:42:30 UTC
struct Base
  virtual auto f () const -> int = 0;

struct Derived : public Base
  virtual auto f () const -> int override { return 0; }

int main() { Derived d; }

The above fails to compile. Errors:

error: expected ';' at end of member declaration
error: 'override' does not name a type

Both errors are reported for the definition of Derived::f. According to the standard, section 8.4.1 Function definitions have the form

attribute-specifier-seqopt decl-specifier-seqopt declarator virt-specifier-seqopt function-body

The declarator in a function-definition shall have the form
  D1 ( parameter-declaration-clause ) cv-qualifier-seqopt
    ref-qualifieropt exception-specificationopt attribute-specifier-seqopt trailing-return-typeopt

Since the declarator includes the trailing return type, I believe the above should compile.

If the override specifier is moved before the -> the code does compile, but that doesn't jive with the standard.
Comment 1 Daniel Krügler 2012-10-07 18:02:17 UTC
The example works in 4.8 HEAD.
Comment 2 Paolo Carlini 2012-10-07 18:04:52 UTC
Indeed it does.