Bug 98286 - g++ accepts 'void d(void) { typename foo; }' as valid
Summary: g++ accepts 'void d(void) { typename foo; }' as valid
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 10.2.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Keywords: accepts-invalid
Depends on:
Reported: 2020-12-15 09:11 UTC by Sergei Trofimovich
Modified: 2021-08-26 21:23 UTC (History)
2 users (show)

See Also:
Known to work:
Known to fail: 7.5.0
Last reconfirmed: 2021-08-26 00:00:00


Note You need to log in before you can comment on or make changes to this bug.
Description Sergei Trofimovich 2020-12-15 09:11:15 UTC
Extracted from larger confusing boost example where g++ and clang++ disagree on syntactic validity. Filing a small one:

    $ cat bug.cpp
    void d(void) { typename foo; }

$ g++-11.0.0 -c bug.cpp -Wall -Wextra
bug.cpp: In function 'void d()':
bug.cpp:1:25: warning: unused variable 'foo' [-Wunused-variable]
    1 | void d(void) { typename foo; }
      |                         ^~~

$ clang++ -c bug.cpp -Wall -Wextra
bug.cpp:1:25: error: expected a qualified name after 'typename'
void d(void) { typename foo; }
bug.cpp:1:25: error: C++ requires a type specifier for all declarations
2 errors generated.

It looks like g++ interpreted 'typename foo;' as 'int foo'.

Should the example compile?
Comment 1 Andrew Pinski 2020-12-15 09:14:52 UTC