From: Richard Smith Date: Mon, 29 Apr 2013 08:45:27 +0000 (+0000) Subject: Fix an assertion failure / accepts-invalid in -fms-extensions mode. Don't build X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=97aea95f46f27ff0927faa72baa7fe2b0bce1d2d;p=clang Fix an assertion failure / accepts-invalid in -fms-extensions mode. Don't build a dependent-scope id expression when a templated member function of a non-templated class references an unknown identifier, since instantiation won't rebuild it (and we can tell at parse time that it'll never work). Based on a patch by Faisal Vali! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@180701 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index a0e6c2144e..f5900c06c7 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -1916,15 +1916,17 @@ ExprResult Sema::ActOnIdExpression(Scope *S, // If this name wasn't predeclared and if this is not a function // call, diagnose the problem. if (R.empty()) { - // In Microsoft mode, if we are inside a template class member function - // and we can't resolve an identifier then assume the identifier is type - // dependent. The goal is to postpone name lookup to instantiation time - // to be able to search into type dependent base classes. - if (getLangOpts().MicrosoftMode && CurContext->isDependentContext() && - isa(CurContext)) - return ActOnDependentIdExpression(SS, TemplateKWLoc, NameInfo, - IsAddressOfOperand, TemplateArgs); + // whose parent class has dependent base classes, and we can't resolve + // an identifier, then assume the identifier is type dependent. The + // goal is to postpone name lookup to instantiation time to be able to + // search into the type dependent base classes. + if (getLangOpts().MicrosoftMode) { + CXXMethodDecl *MD = dyn_cast(CurContext); + if (MD && MD->getParent()->hasAnyDependentBases()) + return ActOnDependentIdExpression(SS, TemplateKWLoc, NameInfo, + IsAddressOfOperand, TemplateArgs); + } CorrectionCandidateCallback DefaultValidator; if (DiagnoseEmptyLookup(S, SS, R, CCC ? *CCC : DefaultValidator)) diff --git a/test/SemaTemplate/ms-lookup-template-base-classes.cpp b/test/SemaTemplate/ms-lookup-template-base-classes.cpp index 8f80cb59e8..cb1a7f50b7 100644 --- a/test/SemaTemplate/ms-lookup-template-base-classes.cpp +++ b/test/SemaTemplate/ms-lookup-template-base-classes.cpp @@ -8,7 +8,6 @@ public: void g();// expected-note {{must qualify identifier to find this declaration in dependent base class}} }; - template class B : public A { public: @@ -28,6 +27,31 @@ void test() b.z(3); } +struct A2 { + template void f(T) { + XX; //expected-error {{use of undeclared identifier 'XX'}} + A2::XX; //expected-error {{no member named 'XX' in 'A2'}} + } +}; +template void A2::f(int); + +template +struct A3 { + template void f(T1) { + XX; //expected-error {{use of undeclared identifier 'XX'}} + } +}; +template void A3::f(int); + +template +struct A4 { + void f(char) { + XX; //expected-error {{use of undeclared identifier 'XX'}} + } +}; +template class A4; + + namespace lookup_dependent_bases_id_expr { template class A {