Bug 97475 - An unnamed class with a typedef name for linkage purposes having a method.
Summary: An unnamed class with a typedef name for linkage purposes having a method.
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid
Depends on: 46589
Blocks:
  Show dependency treegraph
 
Reported: 2020-10-17 21:48 UTC by Anders Granlund
Modified: 2021-08-05 13:34 UTC (History)
1 user (show)

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


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Anders Granlund 2020-10-17 21:48:10 UTC
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
Comment 1 Andrew Pinski 2021-08-04 21:43:36 UTC
I think this is a dup of bug 46589.
Comment 2 Jonathan Wakely 2021-08-05 11:32:03 UTC
Well that's about the linkage of such entities, this is about whether they are ill-formed.

The rule that makes this ill-formed was added by https://wg21.link/p1766r1 but was approved as a defect report against previous standards.
Comment 3 Jonathan Wakely 2021-08-05 11:35:07 UTC
Maybe we should make this ill-formed for C++20, and a pedwarn otherwise, so existing code continues to compile using previous standards.
Comment 4 Anders Granlund 2021-08-05 13:34:06 UTC
Sounds good to me!

On Thu, 5 Aug 2021, 13:35 redi at gcc dot gnu.org, <gcc-bugzilla@gcc.gnu.org>
wrote:

> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97475
>
> --- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
> Maybe we should make this ill-formed for C++20, and a pedwarn otherwise, so
> existing code continues to compile using previous standards.
>
> --
> You are receiving this mail because:
> You reported the bug.