From: Richard Smith Date: Fri, 1 Feb 2013 08:25:07 +0000 (+0000) Subject: Fix diagnostic for bad alignas use: it can't be applied to functions. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5f838aa9c82c22b6ed2a0cb090969a706c8a1775;p=clang Fix diagnostic for bad alignas use: it can't be applied to functions. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174160 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index b1f4fb62dc..3e3b816ce2 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -1852,7 +1852,8 @@ def warn_attribute_wrong_decl_type : Warning< "functions, methods and blocks|functions, methods, and classes|" "functions, methods, and parameters|classes|variables|methods|" "variables, functions and labels|fields and global variables|structs|" - "variables, functions and tag types|thread-local variables}1">, + "variables, functions and tag types|thread-local variables|" + "variables and fields|variables, data members and tag types}1">, InGroup; def err_attribute_wrong_decl_type : Error< "%0 attribute only applies to %select{functions|unions|" @@ -1860,7 +1861,8 @@ def err_attribute_wrong_decl_type : Error< "functions, methods and blocks|functions, methods, and classes|" "functions, methods, and parameters|classes|variables|methods|" "variables, functions and labels|fields and global variables|structs|" - "variables, functions and tag types|thread-local variables}1">; + "variables, functions and tag types|thread-local variables|" + "variables and fields|variables, data members and tag types}1">; def warn_function_attribute_wrong_type : Warning< "'%0' only applies to function types; type here is %1">, InGroup; diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index 9409b30e5b..8aedaf7973 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -47,7 +47,9 @@ enum AttributeDeclKind { ExpectedFieldOrGlobalVar, ExpectedStruct, ExpectedVariableFunctionOrTag, - ExpectedTLSVar + ExpectedTLSVar, + ExpectedVariableOrField, + ExpectedVariableFieldOrTag }; //===----------------------------------------------------------------------===// @@ -3323,7 +3325,8 @@ void Sema::AddAlignedAttr(SourceRange AttrRange, Decl *D, Expr *E, } else if (!isa(D)) { Diag(AttrLoc, diag::err_attribute_wrong_decl_type) << (TmpAttr.isC11() ? "'_Alignas'" : "'alignas'") - << ExpectedVariableFunctionOrTag; + << (TmpAttr.isC11() ? ExpectedVariableOrField + : ExpectedVariableFieldOrTag); return; } if (DiagKind != -1) { diff --git a/test/Sema/alignas.c b/test/Sema/alignas.c index a79c738d12..020eff6a14 100644 --- a/test/Sema/alignas.c +++ b/test/Sema/alignas.c @@ -11,7 +11,7 @@ struct align_member { _Alignas(1) char bitfield : 1; // expected-error {{'_Alignas' attribute cannot be applied to a bit-field}} }; -typedef _Alignas(8) char align_typedef; // expected-error {{'_Alignas' attribute only applies to variables, functions and tag types}} +typedef _Alignas(8) char align_typedef; // expected-error {{'_Alignas' attribute only applies to variables and fields}} void f(_Alignas(1) char c) { // expected-error {{'_Alignas' attribute cannot be applied to a function parameter}} _Alignas(1) register char k; // expected-error {{'_Alignas' attribute cannot be applied to a variable with 'register' storage class}} diff --git a/test/SemaCXX/attr-cxx0x.cpp b/test/SemaCXX/attr-cxx0x.cpp index 09103c8907..d1787f186b 100644 --- a/test/SemaCXX/attr-cxx0x.cpp +++ b/test/SemaCXX/attr-cxx0x.cpp @@ -25,7 +25,7 @@ template struct alignas(A) align_class_template {}; template alignas(T...) struct align_class_temp_pack_type {}; // expected-error{{pack expansions in alignment specifiers are not supported yet}} template alignas(A...) struct align_class_temp_pack_expr {}; // expected-error{{pack expansions in alignment specifiers are not supported yet}} -typedef char align_typedef alignas(8); // expected-error {{'alignas' attribute only applies to variables, functions and tag types}} +typedef char align_typedef alignas(8); // expected-error {{'alignas' attribute only applies to variables, data members and tag types}} template using align_alias_template = align_typedef alignas(8); // expected-error {{'alignas' attribute cannot be applied to types}} static_assert(alignof(align_big) == alignof(int), "k's alignment is wrong"); // expected-warning{{'alignof' applied to an expression is a GNU extension}}