]> granicus.if.org Git - clang/commitdiff
Thread safety analysis: prevent a compiler error in cases where a
authorDeLesley Hutchins <delesley@google.com>
Wed, 15 Aug 2012 22:41:04 +0000 (22:41 +0000)
committerDeLesley Hutchins <delesley@google.com>
Wed, 15 Aug 2012 22:41:04 +0000 (22:41 +0000)
late-parsed attribute is attached to an invalid declaration.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@161997 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Parse/ParseDecl.cpp
test/SemaCXX/warn-thread-safety-parsing.cpp

index b830d9ccfd9f81f2b6dc67ba4cd4abf310182ebc..a50f42bf8ba63511d24d9255c600f1de5a2bafa4 100644 (file)
@@ -866,7 +866,8 @@ void Parser::ParseLexedAttributes(ParsingClass &Class) {
 void Parser::ParseLexedAttributeList(LateParsedAttrList &LAs, Decl *D,
                                      bool EnterScope, bool OnDefinition) {
   for (unsigned i = 0, ni = LAs.size(); i < ni; ++i) {
-    LAs[i]->addDecl(D);
+    if (D)
+      LAs[i]->addDecl(D);
     ParseLexedAttribute(*LAs[i], EnterScope, OnDefinition);
     delete LAs[i];
   }
index 3f8a7359088d84bd35e27bb2a3970a4147467573..8aa6a91a9d2d487bab9fdaecb5ee1d1c05af9528 100644 (file)
@@ -1429,4 +1429,14 @@ class Foo {
 }
 
 
+namespace InvalidDeclTest {
+
+class Foo { };
+namespace {
+void Foo::bar(Mutex* mu) LOCKS_EXCLUDED(mu) { } // \
+   // expected-error   {{cannot define or redeclare 'bar' here because namespace '' does not enclose namespace 'Foo'}} \
+   // expected-warning {{attribute locks_excluded ignored, because it is not attached to a declaration}}
+}
+
+} // end namespace InvalidDeclTest