r199962 - PR18560: When switching to a new context, don't just save and restore an

Richard Smith richard-llvm at metafoo.co.uk
Thu Jan 23 17:54:53 PST 2014


Author: rsmith
Date: Thu Jan 23 19:54:52 2014
New Revision: 199962

URL: http://llvm.org/viewvc/llvm-project?rev=199962&view=rev
Log:
PR18560: When switching to a new context, don't just save and restore an
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).

Modified:
    cfe/trunk/include/clang/Sema/Sema.h
    cfe/trunk/lib/Sema/TreeTransform.h
    cfe/trunk/test/SemaCXX/member-init.cpp

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=199962&r1=199961&r2=199962&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Thu Jan 23 19:54:52 2014
@@ -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() {

Modified: cfe/trunk/lib/Sema/TreeTransform.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransform.h?rev=199962&r1=199961&r2=199962&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/TreeTransform.h (original)
+++ cfe/trunk/lib/Sema/TreeTransform.h Thu Jan 23 19:54:52 2014
@@ -8339,7 +8339,8 @@ TreeTransform<Derived>::TransformLambdaS
   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.

Modified: cfe/trunk/test/SemaCXX/member-init.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/member-init.cpp?rev=199962&r1=199961&r2=199962&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/member-init.cpp (original)
+++ cfe/trunk/test/SemaCXX/member-init.cpp Thu Jan 23 19:54:52 2014
@@ -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(); };
+}





More information about the cfe-commits mailing list