r204753 - -fms-compatibility: Only form implicit member exprs for unqualified ids

Reid Kleckner reid at kleckner.net
Tue Mar 25 13:31:28 PDT 2014


Author: rnk
Date: Tue Mar 25 15:31:28 2014
New Revision: 204753

URL: http://llvm.org/viewvc/llvm-project?rev=204753&view=rev
Log:
-fms-compatibility: Only form implicit member exprs for unqualified ids

If there are any scope specifiers, then a base class must be named or
the symbol isn't from a base class.

Fixes PR19233.

Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/SemaTemplate/ms-lookup-template-base-classes.cpp

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=204753&r1=204752&r2=204753&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Mar 25 15:31:28 2014
@@ -2044,17 +2044,17 @@ ExprResult Sema::ActOnIdExpression(Scope
     if (R.empty()) {
       // In Microsoft mode, if we are inside a template class member function
       // whose parent class has dependent base classes, and we can't resolve
-      // an identifier, then assume the identifier is a member of a dependent
-      // base class.  The goal is to postpone name lookup to instantiation time
-      // to be able to search into the type dependent base classes.
+      // an unqualified identifier, then assume the identifier is a member of a
+      // dependent base class.  The goal is to postpone name lookup to
+      // instantiation time to be able to search into the type dependent base
+      // classes.
       // FIXME: If we want 100% compatibility with MSVC, we will have delay all
       // unqualified name lookup.  Any name lookup during template parsing means
       // clang might find something that MSVC doesn't.  For now, we only handle
       // the common case of members of a dependent base class.
-      if (getLangOpts().MSVCCompat) {
+      if (SS.isEmpty() && getLangOpts().MSVCCompat) {
         CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(CurContext);
         if (MD && MD->isInstance() && MD->getParent()->hasAnyDependentBases()) {
-          assert(SS.isEmpty() && "qualifiers should be already handled");
           QualType ThisType = MD->getThisType(Context);
           // Since the 'this' expression is synthesized, we don't need to
           // perform the double-lookup check.

Modified: cfe/trunk/test/SemaTemplate/ms-lookup-template-base-classes.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/ms-lookup-template-base-classes.cpp?rev=204753&r1=204752&r2=204753&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/ms-lookup-template-base-classes.cpp (original)
+++ cfe/trunk/test/SemaTemplate/ms-lookup-template-base-classes.cpp Tue Mar 25 15:31:28 2014
@@ -236,3 +236,26 @@ template <typename T> struct D : T {
 template struct D<A>;
 
 }
+
+namespace PR19233 {
+template <class T>
+struct A : T {
+  void foo() {
+    ::undef(); // expected-error {{no member named 'undef' in the global namespace}}
+  }
+  void bar() {
+    ::UndefClass::undef(); // expected-error {{no member named 'UndefClass' in the global namespace}}
+  }
+  void baz() {
+    B::qux(); // expected-error {{use of undeclared identifier 'B'}}
+  }
+};
+
+struct B { void qux(); };
+struct C : B { };
+template struct A<C>; // No error!  B is a base of A<C>, and qux is available.
+
+struct D { };
+template struct A<D>; // expected-note {{in instantiation of member function 'PR19233::A<PR19233::D>::baz' requested here}}
+
+}





More information about the cfe-commits mailing list