This revision was automatically updated to reflect the committed changes. Closed by commit rGa603f566dbe0: [clang] CWG 2354: prohibit alignas for enums (authored by Endill, committed by ChuanqiXu).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D121723/new/ https://reviews.llvm.org/D121723 Files: clang/include/clang/Basic/DiagnosticSemaKinds.td clang/lib/Sema/SemaDeclAttr.cpp clang/test/CXX/dcl.dcl/dcl.attr/dcl.align/p5.cpp clang/test/CXX/dcl.dcl/dcl.attr/dcl.align/p6.cpp clang/test/CXX/drs/dr2354.cpp clang/www/cxx_dr_status.html
Index: clang/www/cxx_dr_status.html =================================================================== --- clang/www/cxx_dr_status.html +++ clang/www/cxx_dr_status.html @@ -13938,7 +13938,7 @@ <td><a href="https://wg21.link/cwg2354">2354</a></td> <td>CD5</td> <td>Extended alignment and object representation</td> - <td class="none" align="center">Unknown</td> + <td class="unreleased" align="center">Clang 15</td> </tr> <tr class="open" id="2355"> <td><a href="https://wg21.link/cwg2355">2355</a></td> Index: clang/test/CXX/drs/dr2354.cpp =================================================================== --- /dev/null +++ clang/test/CXX/drs/dr2354.cpp @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -x c++ -verify %s + +// dr2354: 15 + +namespace DR2354 { + +enum alignas(64) A {}; // expected-error {{'alignas' attribute cannot be applied to an enumeration}} +enum struct alignas(64) B {}; // expected-error {{'alignas' attribute cannot be applied to an enumeration}} + +} // namespace DR2354 Index: clang/test/CXX/dcl.dcl/dcl.attr/dcl.align/p6.cpp =================================================================== --- clang/test/CXX/dcl.dcl/dcl.attr/dcl.align/p6.cpp +++ clang/test/CXX/dcl.dcl/dcl.attr/dcl.align/p6.cpp @@ -27,21 +27,6 @@ int n9; // expected-error {{'alignas' must be specified on definition if it is specified on any declaration}} alignas(4) extern int n9; // expected-note {{declared with 'alignas' attribute here}} - -enum alignas(2) E : char; // expected-note {{declared with 'alignas' attribute here}} -enum E : char {}; // expected-error {{'alignas' must be specified on definition if it is specified on any declaration}} - -enum alignas(4) F : char; // expected-note {{previous declaration is here}} -enum alignas(2) F : char; // expected-error {{redeclaration has different alignment requirement (2 vs 4)}} - -enum G : char; -enum alignas(8) G : char {}; -enum G : char; - -enum H : char {}; // expected-error {{'alignas' must be specified on definition if it is specified on any declaration}} -enum alignas(1) H : char; // expected-note {{declared with 'alignas' attribute here}} - - struct S; struct alignas(16) S; // expected-note {{declared with 'alignas' attribute here}} struct S; @@ -73,14 +58,5 @@ char *x1848 = X<1,8,4,8>::Buffer; // ok char *x1248 = X<1,2,4,8>::Buffer; // expected-note {{in instantiation of}} -template<int M, int N, int O, int P> struct Y { - enum alignas(M) alignas(N) E : char; -}; -template<int M, int N, int O, int P> -enum alignas(O) alignas(P) Y<M,N,O,P>::E : char { e }; -int y1848 = Y<1,8,4,8>::e; -// FIXME: We should reject this. -int y1248 = Y<1,2,4,8>::e; - // Don't crash here. alignas(4) struct Incomplete incomplete; // expected-error {{incomplete type}} expected-note {{forward declaration}} Index: clang/test/CXX/dcl.dcl/dcl.attr/dcl.align/p5.cpp =================================================================== --- clang/test/CXX/dcl.dcl/dcl.attr/dcl.align/p5.cpp +++ clang/test/CXX/dcl.dcl/dcl.attr/dcl.align/p5.cpp @@ -11,13 +11,6 @@ alignas(8) int n9 alignas(2); // ok, overaligned alignas(1) extern int n10; // expected-error {{less than minimum alignment}} -enum alignas(1) E1 {}; // expected-error {{requested alignment is less than minimum alignment of 4 for type 'E1'}} -enum alignas(1) E2 : char {}; // ok -enum alignas(4) E3 { e3 = 0 }; // ok -enum alignas(4) E4 { e4 = 1ull << 33 }; // expected-error {{requested alignment is less than minimum alignment of 8 for type 'E4'}} -enum alignas(8) E5 {}; -static_assert(alignof(E5) == 8, ""); - typedef __attribute__((aligned(16))) int IntAlign16; enum E6 : IntAlign16 {}; static_assert(alignof(E6) == 4, ""); @@ -62,15 +55,6 @@ template struct X<16, 8, S1>; template struct X<4, 4, S1>; // expected-note {{instantiation}} -template<int N, typename T> -struct Y { - enum alignas(N) E : T {}; // expected-error {{requested alignment is less than minimum}} -}; -template struct Y<1, char>; -template struct Y<2, char>; -template struct Y<1, short>; // expected-note {{instantiation}} -template struct Y<2, short>; - template<int N, typename T> void f() { alignas(N) T v; // expected-error {{requested alignment is less than minimum}} Index: clang/lib/Sema/SemaDeclAttr.cpp =================================================================== --- clang/lib/Sema/SemaDeclAttr.cpp +++ clang/lib/Sema/SemaDeclAttr.cpp @@ -4290,6 +4290,9 @@ // declared with the register storage class specifier. An // alignment-specifier may also be applied to the declaration of a class // or enumeration type. + // CWG 2354: + // CWG agreed to remove permission for alignas to be applied to + // enumerations. // C11 6.7.5/2: // An alignment attribute shall not be specified in a declaration of // a typedef, or a bit-field, or a function, or a parameter, or an @@ -4305,6 +4308,9 @@ } else if (const auto *FD = dyn_cast<FieldDecl>(D)) { if (FD->isBitField()) DiagKind = 3; + } else if (const auto *ED = dyn_cast<EnumDecl>(D)) { + if (ED->getLangOpts().CPlusPlus) + DiagKind = 4; } else if (!isa<TagDecl>(D)) { Diag(AttrLoc, diag::err_attribute_wrong_decl_type) << &TmpAttr << (TmpAttr.isC11() ? ExpectedVariableOrField Index: clang/include/clang/Basic/DiagnosticSemaKinds.td =================================================================== --- clang/include/clang/Basic/DiagnosticSemaKinds.td +++ clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -3022,8 +3022,9 @@ def err_align_value_attribute_argument_not_int : Error< "'align_value' attribute requires integer constant">; def err_alignas_attribute_wrong_decl_type : Error< - "%0 attribute cannot be applied to a %select{function parameter|" - "variable with 'register' storage class|'catch' variable|bit-field}1">; + "%0 attribute cannot be applied to %select{a function parameter|" + "a variable with 'register' storage class|a 'catch' variable|a bit-field|" + "an enumeration}1">; def err_alignas_missing_on_definition : Error< "%0 must be specified on definition if it is specified on any declaration">; def note_alignas_on_declaration : Note<"declared with %0 attribute here">;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits