]> granicus.if.org Git - clang/commitdiff
Fix diagnostic for bad alignas use: it can't be applied to functions.
authorRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 1 Feb 2013 08:25:07 +0000 (08:25 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 1 Feb 2013 08:25:07 +0000 (08:25 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174160 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaDeclAttr.cpp
test/Sema/alignas.c
test/SemaCXX/attr-cxx0x.cpp

index b1f4fb62dc50d672a25a36d8a304f2c398e09988..3e3b816ce29f7433c9e8b8da536664ebb48c2ec8 100644 (file)
@@ -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<IgnoredAttributes>;
 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<IgnoredAttributes>;
index 9409b30e5b0e6b45ab0eaa6a8de99023641b2d37..8aedaf7973e92f279b8afc444247122a34a19b97 100644 (file)
@@ -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<TagDecl>(D)) {
       Diag(AttrLoc, diag::err_attribute_wrong_decl_type)
         << (TmpAttr.isC11() ? "'_Alignas'" : "'alignas'")
-        << ExpectedVariableFunctionOrTag;
+        << (TmpAttr.isC11() ? ExpectedVariableOrField
+                            : ExpectedVariableFieldOrTag);
       return;
     }
     if (DiagKind != -1) {
index a79c738d12d4559367326b27a439b377a457c7f3..020eff6a141c00427fd4f0ddf023dafdc18b3c3a 100644 (file)
@@ -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}}
index 09103c8907af32bd4f18c0d7a12f44df0bb24095..d1787f186bc6b899376ff35de95a91cc8b0f7fb4 100644 (file)
@@ -25,7 +25,7 @@ template <unsigned A> struct alignas(A) align_class_template {};
 template <typename... T> alignas(T...) struct align_class_temp_pack_type {}; // expected-error{{pack expansions in alignment specifiers are not supported yet}}
 template <unsigned... A> 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<typename T> 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}}