[cfe-commits] r85718 - in /cfe/trunk: lib/Sema/SemaExprCXX.cpp test/SemaTemplate/instantiate-method.cpp

Douglas Gregor dgregor at apple.com
Sun Nov 1 09:08:18 PST 2009


Author: dgregor
Date: Sun Nov  1 11:08:18 2009
New Revision: 85718

URL: http://llvm.org/viewvc/llvm-project?rev=85718&view=rev
Log:
Within a template, qualified name lookup can refer to a non-dependent type
that is not known to be a base class at template definition time due
to some dependent base class. Treat qualified name lookup that refers
to a non-static data member or function as implicit class member
access when the "this" type would be dependent.


Modified:
    cfe/trunk/lib/Sema/SemaExprCXX.cpp
    cfe/trunk/test/SemaTemplate/instantiate-method.cpp

Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=85718&r1=85717&r2=85718&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Sun Nov  1 11:08:18 2009
@@ -2395,6 +2395,12 @@
   // Determine whether the declaration(s) we found are actually in a base 
   // class. If not, this isn't an implicit member reference.
   ThisType = MD->getThisType(Context);
+  
+  // If the type of "this" is dependent, we can't tell if the member is in a 
+  // base class or not, so treat this as a dependent implicit member reference.
+  if (ThisType->isDependentType())
+    return true;
+  
   QualType CtxType = Context.getTypeDeclType(cast<CXXRecordDecl>(Ctx));
   QualType ClassType
     = Context.getTypeDeclType(cast<CXXRecordDecl>(MD->getParent()));

Modified: cfe/trunk/test/SemaTemplate/instantiate-method.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-method.cpp?rev=85718&r1=85717&r2=85718&view=diff

==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-method.cpp (original)
+++ cfe/trunk/test/SemaTemplate/instantiate-method.cpp Sun Nov  1 11:08:18 2009
@@ -81,3 +81,20 @@
   int *y0 = x0;
   int *y1 = x1; // expected-error{{initializing}}
 }
+
+struct X0Base {
+  int &f();
+};
+
+template<typename T>
+struct X0 : X0Base {
+};
+
+template<typename U>
+struct X1 : X0<U> {
+  int &f2() { return X0Base::f(); }
+};
+
+void test_X1(X1<int> x1i) {
+  int &ir = x1i.f2();
+}





More information about the cfe-commits mailing list