-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[C23] Fix handling of alignas #81637
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3518,8 +3518,24 @@ void Parser::ParseDeclarationSpecifiers( | |
DS.Finish(Actions, Policy); | ||
return; | ||
|
||
case tok::l_square: | ||
// alignment-specifier | ||
case tok::kw__Alignas: | ||
if (!getLangOpts().C11) | ||
Diag(Tok, diag::ext_c11_feature) << Tok.getName(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Preexisting but no compat warning in C11 mode? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, we should probably add a compat warning here (and in a bunch of other places) -- perhaps a |
||
[[fallthrough]]; | ||
case tok::kw_alignas: | ||
// _Alignas and alignas (C23, not C++) should parse the same way. The C++ | ||
// parsing for alignas happens through the usual attribute parsing. This | ||
// ensures that an alignas specifier can appear in a type position in C | ||
// despite that not being valid in C++. | ||
if (getLangOpts().C23 || Tok.getKind() == tok::kw__Alignas) { | ||
if (Tok.getKind() == tok::kw_alignas) | ||
Diag(Tok, diag::warn_c23_compat_keyword) << Tok.getName(); | ||
ParseAlignmentSpecifier(DS.getAttributes()); | ||
continue; | ||
} | ||
[[fallthrough]]; | ||
case tok::l_square: | ||
if (!isAllowedCXX11AttributeSpecifier()) | ||
goto DoneWithDeclSpec; | ||
|
||
|
@@ -4234,13 +4250,6 @@ void Parser::ParseDeclarationSpecifiers( | |
isInvalid = DS.setFunctionSpecNoreturn(Loc, PrevSpec, DiagID); | ||
break; | ||
|
||
// alignment-specifier | ||
case tok::kw__Alignas: | ||
if (!getLangOpts().C11) | ||
Diag(Tok, diag::ext_c11_feature) << Tok.getName(); | ||
ParseAlignmentSpecifier(DS.getAttributes()); | ||
continue; | ||
|
||
// friend | ||
case tok::kw_friend: | ||
if (DSContext == DeclSpecContext::DSC_class) | ||
|
@@ -5857,6 +5866,11 @@ bool Parser::isDeclarationSpecifier( | |
case tok::kw__Atomic: | ||
return true; | ||
|
||
case tok::kw_alignas: | ||
// alignas is a type-specifier-qualifier in C23, which is a kind of | ||
// declaration-specifier. Outside of C23 mode (including in C++), it is not. | ||
return getLangOpts().C23; | ||
|
||
// GNU ObjC bizarre protocol extension: <proto1,proto2> with implicit 'id'. | ||
case tok::less: | ||
return getLangOpts().ObjC; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,4 @@ | ||
// RUN: %clang_cc1 -std=c23 -fsyntax-only -verify %s | ||
|
||
_Alignas(int) struct c1; // expected-warning {{'_Alignas' attribute ignored}} | ||
|
||
// FIXME: `alignas` enters into C++ parsing code and never reaches the | ||
// declaration specifier attribute diagnostic infrastructure. | ||
// | ||
// Fixing this will require the C23 notions of `alignas` being a keyword and | ||
// `_Alignas` being an alternate spelling integrated into the parsing | ||
// infrastructure. | ||
alignas(int) struct c1; // expected-error {{misplaced attributes; expected attributes here}} | ||
alignas(int) struct c1; // expected-warning {{'alignas' attribute ignored}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should that be in the breaking change section?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can move the code example up there easily enough if you'd like.