]> granicus.if.org Git - clang/commitdiff
When cloning LocalInstantiationScope's, don't update the current scope in Sema.
authorRichard Trieu <rtrieu@google.com>
Wed, 18 Mar 2015 21:52:47 +0000 (21:52 +0000)
committerRichard Trieu <rtrieu@google.com>
Wed, 18 Mar 2015 21:52:47 +0000 (21:52 +0000)
Construction of LocalInstantiationScope automatically updates the current scope
inside Sema.  However, when cloning a scope, the current scope does not change.
Change the cloning function to preserve the current scope.

Review: http://reviews.llvm.org/D8407
BUG: https://llvm.org/bugs/show_bug.cgi?id=22931

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

include/clang/Sema/Template.h
test/SemaCXX/warn-thread-safety-negative.cpp

index 6c34e5862f7c0529e84c4220a404c1013c8a2f59..b822b11126ea930337b042e0eaf45b9aedd07b2e 100644 (file)
@@ -273,6 +273,11 @@ namespace clang {
     /// outermost scope.
     LocalInstantiationScope *cloneScopes(LocalInstantiationScope *Outermost) {
       if (this == Outermost) return this;
+
+      // Save the current scope from SemaRef since the LocalInstantiationScope
+      // will overwrite it on construction
+      LocalInstantiationScope *oldScope = SemaRef.CurrentInstantiationScope;
+
       LocalInstantiationScope *newScope =
         new LocalInstantiationScope(SemaRef, CombineWithOuterScope);
 
@@ -299,6 +304,8 @@ namespace clang {
           newScope->ArgumentPacks.push_back(NewPack);
         }
       }
+      // Restore the saved scope to SemaRef
+      SemaRef.CurrentInstantiationScope = oldScope;
       return newScope;
     }
 
index f88233a60b27da7855804408f5246cffd12b5e3c..f831010293b61f2bbf76828e9bc6b1258ce115d4 100644 (file)
@@ -102,3 +102,20 @@ public:
 };
 
 }  // end namespace SimpleTest
+
+namespace DoubleAttribute {
+
+struct Foo {
+  Mutex &mutex();
+};
+
+template <typename A>
+class TemplateClass {
+  template <typename B>
+  static void Function(Foo *F)
+      EXCLUSIVE_LOCKS_REQUIRED(F->mutex()) UNLOCK_FUNCTION(F->mutex()) {}
+};
+
+void test() { TemplateClass<int> TC; }
+
+}  // end namespace DoubleAttribute