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

Douglas Gregor dgregor at apple.com
Thu Nov 19 16:59:20 PST 2009


Author: dgregor
Date: Thu Nov 19 18:59:20 2009
New Revision: 89425

URL: http://llvm.org/viewvc/llvm-project?rev=89425&view=rev
Log:
When we have a non-dependent expression such as

  A::f

that occurs within a non-static member function with a type-dependent
"this", don't consider this to be a case for introduction of an
implicit "(*this)." to refer to a specific member function unless we
know (at template definition time) that A is a base class of *this.

There is some disagreement here between GCC, EDG, and Clang about the
handling of this case. I believe that Clang now has the correct,
literal interpretation of the standard, but have asked for
clarification (c++std-core-15483).


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=89425&r1=89424&r2=89425&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Thu Nov 19 18:59:20 2009
@@ -2335,11 +2335,6 @@
   // 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=89425&r1=89424&r2=89425&view=diff

==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-method.cpp (original)
+++ cfe/trunk/test/SemaTemplate/instantiate-method.cpp Thu Nov 19 18:59:20 2009
@@ -84,6 +84,8 @@
 
 struct X0Base {
   int &f();
+  int& g(int);
+  static double &g(double);
 };
 
 template<typename T>
@@ -92,9 +94,26 @@
 
 template<typename U>
 struct X1 : X0<U> {
-  int &f2() { return X0Base::f(); }
+  int &f2() { 
+    return X0Base::f(); // expected-error{{call to non-static member function without an object argument}}
+  }
 };
 
 void test_X1(X1<int> x1i) {
   int &ir = x1i.f2();
 }
+
+template<typename U>
+struct X2 : X0Base, U {
+  int &f2() { return X0Base::f(); }
+};
+
+template<typename T>
+struct X3 {
+  void test(T x) {
+    double& d1 = X0Base::g(x);
+  }
+};
+
+
+template struct X3<double>;





More information about the cfe-commits mailing list