]> granicus.if.org Git - clang/commitdiff
Issue warning when late-parsed attributes have no declaration.
authorDeLesley Hutchins <delesley@google.com>
Fri, 2 Mar 2012 22:29:50 +0000 (22:29 +0000)
committerDeLesley Hutchins <delesley@google.com>
Fri, 2 Mar 2012 22:29:50 +0000 (22:29 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@151947 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticParseKinds.td
lib/Parse/ParseDecl.cpp
test/SemaCXX/warn-thread-safety-analysis.cpp

index a97e7d3a229949b417748c4dbd0d2fbeabe0a933..9d726a6624112d56b627e953b4d16e28e983ceb6 100644 (file)
@@ -154,6 +154,9 @@ def err_expected_fn_body : Error<
 def warn_attribute_on_function_definition : Warning<
   "GCC does not allow %0 attribute in this position on a function definition">, 
   InGroup<GccCompat>;
+def warn_attribute_no_decl : Warning<
+  "attribute %0 ignored, because it is not attached to a declaration">, 
+  InGroup<IgnoredAttributes>;
 def err_expected_method_body : Error<"expected method body">;
 def err_invalid_token_after_toplevel_declarator : Error<
   "expected ';' after top level declarator">;
index 476f476dab9af32021592c88cc531b38953db9de..094d53fe60efbf34fce4bb0b62cf4a901b0a0bad 100644 (file)
@@ -774,10 +774,6 @@ void Parser::ParseLexedAttribute(LateParsedAttribute &LA,
   ParsedAttributes Attrs(AttrFactory);
   SourceLocation endLoc;
 
-  // Late parsed attributes must be attached to Decls by hand.  If there
-  // are no Decls, then this was not done properly.
-  assert(LA.Decls.size() > 0 && "No decls attached to late parsed attribute");
-
   if (LA.Decls.size() == 1) {
     Decl *D = LA.Decls[0];
 
@@ -802,10 +798,12 @@ void Parser::ParseLexedAttribute(LateParsedAttribute &LA,
     if (HasTemplateScope) {
       TempScope.Exit();
     }
-  } else {
+  } else if (LA.Decls.size() > 0) {
     // If there are multiple decls, then the decl cannot be within the
     // function scope.
     ParseGNUAttributeArgs(&LA.AttrName, LA.AttrNameLoc, Attrs, &endLoc);
+  } else {
+    Diag(Tok, diag::warn_attribute_no_decl) << LA.AttrName.getName();
   }
 
   for (unsigned i = 0, ni = LA.Decls.size(); i < ni; ++i) {
index ec9f00f94bbbda740657f9e64295e6452d06a9b0..1bf00c224308ad6d3afb7fe0ba2152d21dcc5ac9 100644 (file)
@@ -2155,3 +2155,16 @@ private:
 
 } // end namespace TestMultiDecl
 
+
+namespace WarnNoDecl {
+
+class Foo {
+  void foo(int a);  __attribute__(( // \
+    // expected-warning {{declaration does not declare anything}}
+    exclusive_locks_required(a))); // \
+    // expected-warning {{attribute exclusive_locks_required ignored}}
+};
+
+} // end namespace WarnNoDecl
+
+