From: Kaelyn Uhrain Date: Fri, 8 Jun 2012 01:07:26 +0000 (+0000) Subject: Fix up the 'typename' suggestion logic introduced in r157085, based on X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8c14de83188640bab9cae658e92a655e6d4fd484;p=clang Fix up the 'typename' suggestion logic introduced in r157085, based on feedback from Doug Gregor. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@158185 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp index dccb4b6a61..9cfd9c31e5 100644 --- a/lib/Sema/SemaTemplate.cpp +++ b/lib/Sema/SemaTemplate.cpp @@ -2453,22 +2453,20 @@ bool Sema::CheckTemplateTypeArgument(TemplateTypeParmDecl *Param, NameInfo = ArgExpr->getNameInfo(); } else if (CXXDependentScopeMemberExpr *ArgExpr = dyn_cast(Arg.getAsExpr())) { - SS.Adopt(ArgExpr->getQualifierLoc()); - NameInfo = ArgExpr->getMemberNameInfo(); + if (ArgExpr->isImplicitAccess()) { + SS.Adopt(ArgExpr->getQualifierLoc()); + NameInfo = ArgExpr->getMemberNameInfo(); + } } - if (NameInfo.getName()) { + if (NameInfo.getName().isIdentifier()) { LookupResult Result(*this, NameInfo, LookupOrdinaryName); LookupParsedName(Result, CurScope, &SS); - bool CouldBeType = Result.getResultKind() == - LookupResult::NotFoundInCurrentInstantiation; - - for (LookupResult::iterator I = Result.begin(), IEnd = Result.end(); - !CouldBeType && I != IEnd; ++I) { - CouldBeType = isa(*I); - } - if (CouldBeType) { + if (Result.getAsSingle() || + Result.getResultKind() == + LookupResult::NotFoundInCurrentInstantiation) { + // FIXME: Add a FixIt and fix up the template argument for recovery. SourceLocation Loc = AL.getSourceRange().getBegin(); Diag(Loc, diag::err_template_arg_must_be_type_suggest); Diag(Param->getLocation(), diag::note_template_param_here); diff --git a/test/SemaTemplate/typename-specifier.cpp b/test/SemaTemplate/typename-specifier.cpp index 1d38926c0e..15c13e3bef 100644 --- a/test/SemaTemplate/typename-specifier.cpp +++ b/test/SemaTemplate/typename-specifier.cpp @@ -118,7 +118,7 @@ namespace PR10925 { namespace missing_typename { -template struct pair {}; // expected-note 5 {{template parameter is declared here}} +template struct pair {}; // expected-note 7 {{template parameter is declared here}} template struct map { @@ -132,10 +132,13 @@ class ExampleClass1 { struct ExampleItemSet { typedef ExampleItem* iterator; + ExampleItem* operator[](unsigned); }; void foo() { pair i; // expected-error {{template argument for template type parameter must be a type; did you forget 'typename'?}} + pairExampleItemSet::iterator, int> i; // expected-error-re {{template argument for template type parameter must be a type$}} + pair i; // expected-error-re {{template argument for template type parameter must be a type$}} } pair elt; // expected-error {{template argument for template type parameter must be a type; did you forget 'typename'?}}