https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97475

            Bug ID: 97475
           Summary: An unnamed class with a typedef name for linkage
                    purposes having a method.
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: anders.granlund.0 at gmail dot com
  Target Milestone: ---

Consider the following c++ program:

  typedef struct {
    void f();
  } X;

  int main()
  {
  }

It is not rejected by the compiler when compiling with "-std=c++20
-pedantic-errors".

The expected behaviour is that it should be rejected by section 9.2.3 paragraph
10 in the c++ 20 standard:

"
 10 An unnamed class with a typedef name for linkage purposes shall not
(10.1) — declare any members other than non-static data members, member
enumerations, or member classes,
(10.2) — have any base classes or default member initializers, or
(10.3) — contain a lambda-expression,
and all member classes shall also satisfy these requirements (recursively).
"

Note that clang correctly does reject the program:

  https://godbolt.org/z/rTerza

Reply via email to