Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang allows for multiple declarations introduced by using enum #121334

Open
Rush10233 opened this issue Dec 30, 2024 · 4 comments
Open

clang allows for multiple declarations introduced by using enum #121334

Rush10233 opened this issue Dec 30, 2024 · 4 comments
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" diverges-from:gcc Does the clang frontend diverge from gcc on this issue diverges-from:msvc Does the clang frontend diverge from msvc on this issue

Comments

@Rush10233
Copy link

The following code is accepted by clang under -std=c++20:

struct S2 {
  enum B {
    A
  };
  using enum B ;
};

MSVC and GCC choose to reject it as there would be a name conflict:

<source>:5:16: error: 'using S2::B::A' conflicts with a previous declaration
    5 |   using enum B ;
      |                ^
<source>:3:5: note: previous declaration 'S2::B S2::A'
    3 |     A
      |     ^

While the using enum B statement here actually seems to be meaningless, I'm not quite sure whether this should be rejected or not.

https://godbolt.org/z/3e3aGxnWW

@github-actions github-actions bot added the clang Clang issues not falling into any other category label Dec 30, 2024
@EugeneZelenko EugeneZelenko added clang:frontend Language frontend issues, e.g. anything involving "Sema" diverges-from:gcc Does the clang frontend diverge from gcc on this issue diverges-from:msvc Does the clang frontend diverge from msvc on this issue and removed clang Clang issues not falling into any other category labels Dec 30, 2024
@llvmbot
Copy link
Member

llvmbot commented Dec 30, 2024

@llvm/issue-subscribers-clang-frontend

Author: None (Rush10233)

The following code is accepted by clang under `-std=c++20`:
struct S2 {
  enum B {
    A
  };
  using enum B ;
};

MSVC and GCC choose to reject it as there would be a name conflict:

&lt;source&gt;:5:16: error: 'using S2::B::A' conflicts with a previous declaration
    5 |   using enum B ;
      |                ^
&lt;source&gt;:3:5: note: previous declaration 'S2::B S2::A'
    3 |     A
      |     ^

While the using enum B statement here actually seems to be meaningless, I'm not quite sure whether this should be rejected or not.

https://godbolt.org/z/3e3aGxnWW

@zygoloid
Copy link
Collaborator

Analysis:

So, I think Clang is correct per the wording -- this code is valid. However, there appears to be an intent to prevent multiple / redundant declarations in class scopes in general, and this is the only way to introduce that situation with using declarations, so maybe we should ask CWG if they want this to be valid.

@zygoloid
Copy link
Collaborator

Sent a message to CWG asking for opinions.

@zygoloid
Copy link
Collaborator

This is now CWG2979, and so far it looks like the rules will be changed to make this ill-formed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" diverges-from:gcc Does the clang frontend diverge from gcc on this issue diverges-from:msvc Does the clang frontend diverge from msvc on this issue
Projects
None yet
Development

No branches or pull requests

4 participants