Hi rnk,

Currently the code in SemaCXXScopeSpec does an MSVCCompat fallback to delay 
lookup of possibly dependent base class names. It does so in all template 
bodies, even if the template is a simple function template (in which case there 
can be no dependent base class names.)

Attached patch conditionalizes the compat fallback on whether the template 
function is part of a CXXRecordDecl as well, so that the dependent base class 
lookup workaround only happens when there's a chance of dependent base classes.

See discussion here:
http://permalink.gmane.org/gmane.comp.compilers.clang.devel/38225

http://reviews.llvm.org/D4854

Files:
  lib/Sema/SemaCXXScopeSpec.cpp
  test/SemaTemplate/ms-lookup-template-base-classes.cpp

Index: lib/Sema/SemaCXXScopeSpec.cpp
===================================================================
--- lib/Sema/SemaCXXScopeSpec.cpp
+++ lib/Sema/SemaCXXScopeSpec.cpp
@@ -702,7 +702,8 @@
   // };
   if (getLangOpts().MSVCCompat) {
     DeclContext *DC = LookupCtx ? LookupCtx : CurContext;
-    if (DC->isDependentContext() && DC->isFunctionOrMethod()) {
+    if (DC->isDependentContext() && DC->isFunctionOrMethod() &&
+        isa<CXXRecordDecl>(DC->getParent())) {
       SS.Extend(Context, &Identifier, IdentifierLoc, CCLoc);
       return false;
     }
Index: test/SemaTemplate/ms-lookup-template-base-classes.cpp
===================================================================
--- test/SemaTemplate/ms-lookup-template-base-classes.cpp
+++ test/SemaTemplate/ms-lookup-template-base-classes.cpp
@@ -460,3 +460,11 @@
   int x = f<NameFromBase>();
 };
 }
+
+namespace function_template_undef_impl {
+template<class T>
+void f() {
+  Undef::staticMethod();  // expected-error {{use of undeclared identifier 
'Undef'}}
+  UndefVar.method(); // expected-error {{use of undeclared identifier 
'UndefVar'}}
+}
+}
Index: lib/Sema/SemaCXXScopeSpec.cpp
===================================================================
--- lib/Sema/SemaCXXScopeSpec.cpp
+++ lib/Sema/SemaCXXScopeSpec.cpp
@@ -702,7 +702,8 @@
   // };
   if (getLangOpts().MSVCCompat) {
     DeclContext *DC = LookupCtx ? LookupCtx : CurContext;
-    if (DC->isDependentContext() && DC->isFunctionOrMethod()) {
+    if (DC->isDependentContext() && DC->isFunctionOrMethod() &&
+        isa<CXXRecordDecl>(DC->getParent())) {
       SS.Extend(Context, &Identifier, IdentifierLoc, CCLoc);
       return false;
     }
Index: test/SemaTemplate/ms-lookup-template-base-classes.cpp
===================================================================
--- test/SemaTemplate/ms-lookup-template-base-classes.cpp
+++ test/SemaTemplate/ms-lookup-template-base-classes.cpp
@@ -460,3 +460,11 @@
   int x = f<NameFromBase>();
 };
 }
+
+namespace function_template_undef_impl {
+template<class T>
+void f() {
+  Undef::staticMethod();  // expected-error {{use of undeclared identifier 'Undef'}}
+  UndefVar.method(); // expected-error {{use of undeclared identifier 'UndefVar'}}
+}
+}
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to