]> granicus.if.org Git - clang/commitdiff
PR18560: When switching to a new context, don't just save and restore an
authorRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 24 Jan 2014 01:54:52 +0000 (01:54 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 24 Jan 2014 01:54:52 +0000 (01:54 +0000)
override for the type of 'this', also clear it out (unless we're entering the
context of a lambda-expression, where it should be inherited).

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

include/clang/Sema/Sema.h
lib/Sema/TreeTransform.h
test/SemaCXX/member-init.cpp

index f11cb9ca93a0348ba6587d1d292a95d398339539..12a4116f01fb7f7aee299254c231e7e2a5247c32 100644 (file)
@@ -479,13 +479,15 @@ public:
     QualType SavedCXXThisTypeOverride;
 
   public:
-    ContextRAII(Sema &S, DeclContext *ContextToPush)
+    ContextRAII(Sema &S, DeclContext *ContextToPush, bool NewThisContext = true)
       : S(S), SavedContext(S.CurContext),
         SavedContextState(S.DelayedDiagnostics.pushUndelayed()),
         SavedCXXThisTypeOverride(S.CXXThisTypeOverride)
     {
       assert(ContextToPush && "pushing null context");
       S.CurContext = ContextToPush;
+      if (NewThisContext)
+        S.CXXThisTypeOverride = QualType();
     }
 
     void pop() {
index 787581d35be4fcedf52600d270eecfe281cbbe92..27380f8c8d44df980b9fbfb5c6548c9a4c03cb61 100644 (file)
@@ -8339,7 +8339,8 @@ TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
   bool Invalid = false;
 
   // Introduce the context of the call operator.
-  Sema::ContextRAII SavedContext(getSema(), CallOperator);
+  Sema::ContextRAII SavedContext(getSema(), CallOperator,
+                                 /*NewThisContext*/false);
 
   LambdaScopeInfo *const LSI = getSema().getCurLambda();
   // Enter the scope of the lambda.
index 6e4fd5df5a08a6b1f7fc96b78fcfdc8040a81b40..d8a00b3b1e24d87fe0595be350e091509e5568f0 100644 (file)
@@ -100,3 +100,13 @@ namespace rdar14084171 {
   };
   void f(Sprite& x) { x = x; }
 }
+
+namespace PR18560 {
+  struct X { int m; };
+
+  template<typename T = X,
+           typename U = decltype(T::m)>
+  int f();
+
+  struct Y { int b = f(); };
+}