Bug 91760 - Trailing return type breaks final specifier
Summary: Trailing return type breaks final specifier
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 10.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2019-09-12 19:28 UTC by James Smith
Modified: 2021-12-09 06:42 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2021-08-07 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description James Smith 2019-09-12 19:28:01 UTC
The following code:

struct final;
struct test
{
    virtual auto foo() -> int final;
};

Generates this error:

error: two or more data types in declaration of 'type name'

Example: https://godbolt.org/z/4GSoW_

The same code works fine on clang (https://godbolt.org/z/4d3J85), MSVC (https://godbolt.org/z/BYq2yW) and ICC (https://godbolt.org/z/_V9Qvd).

Since final and override are "identifiers with special meaning", this code should compile as there is no ambiguity on whether or not "final" can be an identifier in this context.

If the trailing return type is changed to a normal return type, this of course will compile as expected (https://godbolt.org/z/ReWHag):

struct final;
struct test
{
    virtual int foo() final;
};
Comment 1 Martin Liška 2020-01-29 12:22:37 UTC
Confirmed.
Comment 2 Andrew Pinski 2021-12-09 06:42:06 UTC
override has the same issue, see PR 64794.