]> granicus.if.org Git - clang/commitdiff
Remove a non-gcc-compatible extension that would apply attributes on declarations...
authorEli Friedman <eli.friedman@gmail.com>
Sat, 17 Dec 2011 00:36:09 +0000 (00:36 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Sat, 17 Dec 2011 00:36:09 +0000 (00:36 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146796 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticGroups.td
include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaDecl.cpp
test/CXX/temp/temp.decls/temp.variadic/p5.cpp
test/CodeGenCXX/visibility.cpp
test/Sema/attr-declspec-ignored.c [new file with mode: 0644]
test/Sema/attr-deprecated.c
test/Sema/warn-cast-align.c
test/SemaCXX/attr-cxx0x.cpp
test/SemaCXX/attr-declspec-ignored.cpp [new file with mode: 0644]

index e69312e37a24ee63faa1d59333bd36de59576dbb..d9c078f8806e28779d9c7c33f1a60f202f7ca220 100644 (file)
@@ -186,6 +186,7 @@ def UninitializedMaybe : DiagGroup<"conditional-uninitialized">;
 def UnknownPragmas : DiagGroup<"unknown-pragmas">;
 def NSobjectAttribute : DiagGroup<"NSObject-attribute">;
 def UnknownAttributes : DiagGroup<"attributes">;
+def IgnoredAttributes : DiagGroup<"ignored-attributes">;
 def UnnamedTypeTemplateArgs : DiagGroup<"unnamed-type-template-args",
                                         [CXX98CompatUnnamedTypeTemplateArgs]>;
 def UnusedArgument : DiagGroup<"unused-argument">;
index aa6fe86081055d37ddc57dcae386c32d42f7e29a..c0676dd3e1dc2b81cc3f67448e47f528acf4b8c4 100644 (file)
@@ -1465,6 +1465,8 @@ def warn_redeclaration_without_attribute_prev_attribute_ignored : Warning<
 def warn_attribute_ignored : Warning<"%0 attribute ignored">;
 def warn_unknown_attribute_ignored : Warning<
   "unknown attribute %0 ignored">, InGroup<UnknownAttributes>;
+def warn_declspec_attribute_ignored : Warning<
+  "attribute %0 is ignored, place it after \"%select{class|struct|union|enum}1\" to apply attribute to type declaration">, InGroup<IgnoredAttributes>;
 def warn_attribute_precede_definition : Warning<
   "attribute declaration must precede definition">;
 def warn_attribute_void_function_method : Warning<
index 5edeab416d62e1ece5239fddfe0c0465a6934e2d..a0291afeedb11598b7d606fe8dddbecfda649e00 100644 (file)
@@ -2367,8 +2367,6 @@ Decl *Sema::ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS,
   bool emittedWarning = false;
          
   if (RecordDecl *Record = dyn_cast_or_null<RecordDecl>(Tag)) {
-    ProcessDeclAttributeList(S, Record, DS.getAttributes().getList());
-    
     if (!Record->getDeclName() && Record->isCompleteDefinition() &&
         DS.getStorageClassSpec() != DeclSpec::SCS_typedef) {
       if (getLangOptions().CPlusPlus ||
@@ -2463,7 +2461,27 @@ Decl *Sema::ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS,
       << Tag->getTagKind()
       << FixItHint::CreateRemoval(DS.getModulePrivateSpecLoc());
 
-  // FIXME: Warn on useless attributes
+  // Warn about ignored type attributes, for example:
+  // __attribute__((aligned)) struct A;
+  // Attributes should be placed after tag to apply to type declaration.
+  if (!DS.getAttributes().empty()) {
+    DeclSpec::TST TypeSpecType = DS.getTypeSpecType();
+    if (TypeSpecType == DeclSpec::TST_class ||
+        TypeSpecType == DeclSpec::TST_struct ||
+        TypeSpecType == DeclSpec::TST_union ||
+        TypeSpecType == DeclSpec::TST_enum) {
+      AttributeList* attrs = DS.getAttributes().getList();
+      while (attrs) {
+        Diag(attrs->getScopeLoc(),
+             diag::warn_declspec_attribute_ignored)
+        << attrs->getName()
+        << (TypeSpecType == DeclSpec::TST_class ? 0 :
+            TypeSpecType == DeclSpec::TST_struct ? 1 :
+            TypeSpecType == DeclSpec::TST_union ? 2 : 3);
+        attrs = attrs->getNext();
+      }
+    }
+  }
 
   return TagD;
 }
index a0b55804b94a871941ccba74246b70d5e4492576..bbdf489796bb3e3d3a53a4a5352581b9c25fd1ed 100644 (file)
@@ -162,8 +162,7 @@ struct TestUnexpandedTTP {
 // Test for unexpanded parameter packs in declarations.
 template<typename T, typename... Types>
 // FIXME: this should test that the diagnostic reads "type contains..."
-alignas(Types) // expected-error{{expression contains unexpanded parameter pack 'Types'}}
-struct TestUnexpandedDecls : T{
+struct alignas(Types) TestUnexpandedDecls : T{ // expected-error{{expression contains unexpanded parameter pack 'Types'}}
   void member_function(Types);  // expected-error{{declaration type contains unexpanded parameter pack 'Types'}}
   void member_function () throw(Types); // expected-error{{declaration type contains unexpanded parameter pack 'Types'}}
   operator Types() const; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}}
index 0f36a6a753248ae90b6a6e3420cae35486318b9c..0da55c63d63db13c859d7efdf2726d1c2b8c1128 100644 (file)
@@ -156,7 +156,7 @@ namespace Test9 {
 namespace Test10 {
   struct A;
 
-  DEFAULT class B {
+  class DEFAULT B {
     void foo(A*);
   };
 
diff --git a/test/Sema/attr-declspec-ignored.c b/test/Sema/attr-declspec-ignored.c
new file mode 100644 (file)
index 0000000..e1bce47
--- /dev/null
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only\r
+\r
+__attribute__((visibility("hidden")))  __attribute__((aligned)) struct A; // expected-warning{{attribute 'visibility' is ignored, place it after "struct" to apply attribute to type declaration}} \\r
+// expected-warning{{attribute 'aligned' is ignored, place it after "struct" to apply attribute to type declaration}}\r
+__attribute__((visibility("hidden")))  __attribute__((aligned)) union B; // expected-warning{{attribute 'visibility' is ignored, place it after "union" to apply attribute to type declaration}} \\r
+// expected-warning{{attribute 'aligned' is ignored, place it after "union" to apply attribute to type declaration}} \r
+__attribute__((visibility("hidden")))  __attribute__((aligned)) enum C {C}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum" to apply attribute to type declaration}} \\r
+// expected-warning{{attribute 'aligned' is ignored, place it after "enum" to apply attribute to type declaration}}\r
+\r
+__attribute__((visibility("hidden")))  __attribute__((aligned)) struct D {} d;\r
+__attribute__((visibility("hidden")))  __attribute__((aligned)) union E {} e;\r
+__attribute__((visibility("hidden")))  __attribute__((aligned)) enum F {F} f;\r
index 86ee80ef06df7f3064cafe65dfdcf8e1a6d526d2..4760dabc4cd64766549001014585d369446e51a2 100644 (file)
@@ -44,8 +44,8 @@ void test1(struct foo *F) {
 typedef struct foo foo_dep __attribute__((deprecated));
 foo_dep *test2;    // expected-warning {{'foo_dep' is deprecated}}
 
-struct bar_dep __attribute__((deprecated, 
-                              invalid_attribute));  // expected-warning {{unknown attribute 'invalid_attribute' ignored}}
+struct __attribute__((deprecated, 
+                      invalid_attribute)) bar_dep ;  // expected-warning {{unknown attribute 'invalid_attribute' ignored}}
 
 struct bar_dep *test3;   // expected-warning {{'bar_dep' is deprecated}}
 
index 93352c253a2e753c996d811c5f422612679db499..9d64699bb5b4e486f865b72b7aa024ff5e9e3731 100644 (file)
@@ -28,7 +28,7 @@ void test1(void *P) {
 }
 
 // Aligned struct.
-__attribute__((aligned(16))) struct A {
+struct __attribute__((aligned(16))) A {
   char buffer[16];
 };
 void test2(char *P) {
index c697a7d152328022749b05a0d2768b656cf9e918..4281895f40ed9b1c451b18c638c8906fea634ef6 100644 (file)
@@ -9,7 +9,7 @@ struct align_member {
   int member alignas(8);
 };
 
-template <unsigned A> alignas(A) struct align_class_template {};
+template <unsigned A> struct alignas(A) align_class_template {};
 
 // FIXME: these should not error
 template <typename... T> alignas(T...) struct align_class_temp_pack_type {}; // expected-error{{pack expansions in alignment specifiers are not supported yet}}
diff --git a/test/SemaCXX/attr-declspec-ignored.cpp b/test/SemaCXX/attr-declspec-ignored.cpp
new file mode 100644 (file)
index 0000000..c6745c4
--- /dev/null
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only\r
+\r
+namespace test1 {\r
+  __attribute__((visibility("hidden")))  __attribute__((aligned)) class A; // expected-warning{{attribute 'visibility' is ignored, place it after "class" to apply attribute to type declaration}} \\r
+  // expected-warning{{attribute 'aligned' is ignored, place it after "class" to apply attribute to type declaration}}\r
+  __attribute__((visibility("hidden")))  __attribute__((aligned)) struct B; // expected-warning{{attribute 'visibility' is ignored, place it after "struct" to apply attribute to type declaration}} \\r
+  // expected-warning{{attribute 'aligned' is ignored, place it after "struct" to apply attribute to type declaration}}\r
+  __attribute__((visibility("hidden")))  __attribute__((aligned)) union C; // expected-warning{{attribute 'visibility' is ignored, place it after "union" to apply attribute to type declaration}} \\r
+  // expected-warning{{attribute 'aligned' is ignored, place it after "union" to apply attribute to type declaration}} \r
+  __attribute__((visibility("hidden")))  __attribute__((aligned)) enum D {D}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum" to apply attribute to type declaration}} \\r
+  // expected-warning{{attribute 'aligned' is ignored, place it after "enum" to apply attribute to type declaration}}\r
+}\r
+\r
+namespace test2 {\r
+  __attribute__((visibility("hidden")))  __attribute__((aligned)) class A {} a;\r
+  __attribute__((visibility("hidden")))  __attribute__((aligned)) struct B {} b;\r
+  __attribute__((visibility("hidden")))  __attribute__((aligned)) union C {} c;\r
+  __attribute__((visibility("hidden")))  __attribute__((aligned)) enum D {D} d;\r
+}\r