This changes the diagnostic for _Alignas so it no longer tells people to place _Alignas after the "struct" keyword.
Details
Diff Detail
Event Timeline
Thank you for the fix, please be sure to add a release note for the fix as well. Also, I'd like to see some additional C++ test coverage for: alignas(int) struct S {}; to demonstrate we still suggest moving the keyword in that case.
clang/lib/Sema/SemaDecl.cpp | ||
---|---|---|
5296 | I think this isn't quite right -- it'll return true in C++ for alignas: alignas(int) struct S {}; will give the wrong diagnostic now, I suspect. You need to check the language mode as well to ensure we're not in C++ mode. | |
5299–5304 | ||
5312–5317 | Pretty sure you can use something like this instead now. | |
clang/test/C/drs/dr4xx.c | ||
167 | This diagnostic is incorrect but should be fixed with the suggested edit above. | |
clang/test/Parser/c1x-alignas.c | ||
12–13 | Same here. |
@theo-lw -- are you planning to continue working on this review? (It's okay if you're not, I'm more wondering if I should remove you as the assignee on https://github.com/llvm/llvm-project/issues/58637)
No worries, it happens! Thank you for continuing work on this -- if you find you don't have the time, it's not a big deal, just let us know. :-)
Rebased on the main branch & addressed comments.
Added additional test case for C++ alignas.
clang/lib/Sema/SemaDecl.cpp | ||
---|---|---|
5337–5346 | I think this might be a bit more clear: unsigned DiagID; if (AL.isC11AlignasAttribute()) { // Don't use the message with placement with _Alignas. // This is because C doesnt let you use _Alignas on type declarations. DiagID = diag::warn_attribute_ignored; } else if (AL.isRegularKeywordAttribute()) DiagID = diag::err_declspec_keyword_has_no_effect; else DiagID = diag::warn_declspec_attribute_ignored; Diag(AL.getLoc(), DiagID) << AL << GetDiagnosticTypeSpecifierID(DS); | |
clang/test/Parser/c1x-alignas.c | ||
12 | I'd like to see a C23-specific test that does: alignas(int) struct c7; (the test doesn't have to be in this file, but it's to validate that we correctly handle alignas when it's a keyword that aliases to _Alignas.) |
I think this isn't quite right -- it'll return true in C++ for alignas: alignas(int) struct S {}; will give the wrong diagnostic now, I suspect. You need to check the language mode as well to ensure we're not in C++ mode.