diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index b2ac7d98d543..530fc668f2fd 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -105,6 +105,12 @@ static NamedDecl *isAcceptableTemplateName(ASTContext &Context, return nullptr; } + // 'using Dependent::foo;' can resolve to a template name. + // 'using typename Dependent::foo;' cannot (not even if 'foo' is an + // injected-class-name). + if (isa(D)) + return D; + return nullptr; } @@ -214,6 +220,10 @@ TemplateNameKind Sema::isTemplateName(Scope *S, // We'll do this lookup again later. R.suppressDiagnostics(); + } else if (isa((*R.begin())->getUnderlyingDecl())) { + // We don't yet know whether this is a template-name or not. + MemberOfUnknownSpecialization = true; + return TNK_Non_template; } else { TemplateDecl *TD = cast((*R.begin())->getUnderlyingDecl()); @@ -429,7 +439,7 @@ bool Sema::LookupTemplateName(LookupResult &Found, if (ExampleLookupResult && TemplateKWLoc.isValid()) { Diag(Found.getNameLoc(), diag::err_template_kw_refers_to_non_template) << Found.getLookupName() << SS.getRange(); - Diag(ExampleLookupResult->getLocation(), + Diag(ExampleLookupResult->getUnderlyingDecl()->getLocation(), diag::note_template_kw_refers_to_non_template) << Found.getLookupName(); return true; diff --git a/clang/test/CXX/drs/dr1xx.cpp b/clang/test/CXX/drs/dr1xx.cpp index 1507c67b9d8d..a92501128b5f 100644 --- a/clang/test/CXX/drs/dr1xx.cpp +++ b/clang/test/CXX/drs/dr1xx.cpp @@ -71,8 +71,7 @@ namespace dr109 { // dr109: yes using T::template f; // expected-error {{'template' keyword not permitted here}} expected-error {{using declaration cannot refer to a template specialization}} // FIXME: We shouldn't suggest using the 'template' keyword in a location where it's not valid. using T::f; // expected-error {{use 'template' keyword}} expected-error {{using declaration cannot refer to a template specialization}} - // FIXME: The first 'using' above introduces 'f' as a non-template member of 'B', leading to bad recovery: - void g() { this->f(123); } // expected-error {{expected '('}} + void g() { this->f(123); } // expected-error {{use 'template' keyword}} }; } diff --git a/clang/test/SemaTemplate/dependent-names.cpp b/clang/test/SemaTemplate/dependent-names.cpp index 070c7e410f16..05ef33b535a3 100644 --- a/clang/test/SemaTemplate/dependent-names.cpp +++ b/clang/test/SemaTemplate/dependent-names.cpp @@ -427,3 +427,23 @@ namespace DependentTemplateIdWithNoArgs { }; void g() { f(); } } + +namespace DependentUnresolvedUsingTemplate { + template + struct X : T { + using T::foo; + void f() { this->template foo(); } // expected-error {{does not refer to a template}} + void g() { this->template foo<>(); } // expected-error {{does not refer to a template}} + void h() { this->template foo(); } // expected-error {{does not refer to a template}} + }; + struct A { template int foo(); }; + struct B { int foo(); }; // expected-note 3{{non-template here}} + void test(X xa, X xb) { + xa.f(); + xa.g(); + xa.h(); + xb.f(); // expected-note {{instantiation of}} + xb.g(); // expected-note {{instantiation of}} + xb.h(); // expected-note {{instantiation of}} + } +}