[PATCH] Only use MSVC-compatible dependent base class hack for class template members.

Kim Gräsman kim.grasman at gmail.com
Mon Aug 11 14:56:50 PDT 2014


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'}}
+}
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4854.12367.patch
Type: text/x-patch
Size: 1118 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140811/b2571762/attachment.bin>


More information about the cfe-commits mailing list