From 9eaab4be04986319ae8c75c933fbe7de9ab48d68 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Fri, 1 Feb 2013 08:25:07 +0000 Subject: [PATCH] Fix diagnostic for bad alignas use: it can't be applied to functions. llvm-svn: 174160 --- clang/include/clang/Basic/DiagnosticSemaKinds.td | 6 ++++-- clang/lib/Sema/SemaDeclAttr.cpp | 7 +++++-- clang/test/Sema/alignas.c | 2 +- clang/test/SemaCXX/attr-cxx0x.cpp | 2 +- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index b1f4fb62dc50..3e3b816ce29f 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/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/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index 9409b30e5b0e..8aedaf7973e9 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/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/clang/test/Sema/alignas.c b/clang/test/Sema/alignas.c index a79c738d12d4..020eff6a141c 100644 --- a/clang/test/Sema/alignas.c +++ b/clang/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/clang/test/SemaCXX/attr-cxx0x.cpp b/clang/test/SemaCXX/attr-cxx0x.cpp index 09103c8907af..d1787f186bc6 100644 --- a/clang/test/SemaCXX/attr-cxx0x.cpp +++ b/clang/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}}