-
Notifications
You must be signed in to change notification settings - Fork 11.8k
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
Enum tag not in scope inside its (fixed underlying) enum type specifier #70605
Comments
@llvm/issue-subscribers-clang-frontend Author: Alex Shpilkin (alexshpilkin)
Quoth C23 draft [N3096](https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3096.pdf) in 6.2.1p7 (I haven’t seen the more recent but paywalled N3149):
> Structure, union, and enumeration tags have scope that begins just after the appearance of the tag in a type specifier that declares the tag. In Clang trunk with struct foo { int x; };
void bar(void) { enum foo : typeof(((struct foo *)0)->x); }
// void baz(void) { enum foo { A = sizeof(((struct foo *)0)->x) }; }
// ^^^ error: use of 'foo' with tag type that does not match previous declaration So this looks to be wrong as far as C23 is concerned. Replacing See also #57836 re this feature in C generally. |
@EugeneZelenko Is this the correct label? I meant to primarily refer to C23, not C++23. If this applies to C++ as well (needs to be checked in the standard, which I’m not really capable of doing), then I’d expect it to be relevant for C++11 and later, not C++23 specifically. |
@alexshpilkin: Sorry for my mistake. |
There is a bug here but it's not what the OP expects, unfortunately. We should be rejecting the declarations in both GCC and ICC have the correct behavior in this case: https://godbolt.org/z/4T7fbPden |
Uh, I wrote this around 12am and might not have been very clear, but very much wanted both |
Quoth C23 draft N3096 in 6.2.1p7 (I haven’t seen the more recent but paywalled N3149):
In Clang trunk with
-std=c23
as well as Clang 16.0.6 with-std=c2x
, on the other hand, I can refer to the enclosing scope’s definition of the tag being declared inside the enum-type-specifier, even though I wouldn’t have been able to do that later inside the enumerator-list:So this looks to be wrong as far as C23 is concerned. Replacing
typeof
bydecltype
, I also see this being accepted in C++ mode with-std=c++11
,c++14
,c++17
andc++20
. I don’t know if that’s correct for C++, but I would be surprised if so, because it’s certainly inconsistent with how the typical instance of the CRTP works.See also #57836 re this feature in C generally.
The text was updated successfully, but these errors were encountered: