diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2019-02-15 00:29:04 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2019-02-15 00:29:04 +0000 |
commit | 40bd10b770813bd1471d46f514545437516aa4ba (patch) | |
tree | 83b1fcbd4b6eeebc595b3323992c12b05d3ed69e /clang/lib/Sema/SemaDecl.cpp | |
parent | a6e8d5e554080ee5483d95313b2958cd25860990 (diff) | |
download | bcm5719-llvm-40bd10b770813bd1471d46f514545437516aa4ba.tar.gz bcm5719-llvm-40bd10b770813bd1471d46f514545437516aa4ba.zip |
Fix implementation of [temp.local]p4.
When a template-name is looked up, we need to give injected-class-name
declarations of class templates special treatment, as they denote a
template rather than a type.
Previously we achieved this by applying a filter to the lookup results
after completing name lookup, but that is incorrect in various ways, not
least of which is that it lost all information about access and how
members were named, and the filtering caused us to generally lose
all ambiguity errors between templates and non-templates.
We now preserve the lookup results exactly, and the few places that need
to map from a declaration found by name lookup into a declaration of a
template do so explicitly. Deduplication of repeated lookup results of
the same injected-class-name declaration is done by name lookup instead
of after the fact.
llvm-svn: 354091
Diffstat (limited to 'clang/lib/Sema/SemaDecl.cpp')
-rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index a9e6eb12c0d..d6e44af0ebe 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -1017,7 +1017,8 @@ Corrected: case LookupResult::Ambiguous: if (getLangOpts().CPlusPlus && NextToken.is(tok::less) && - hasAnyAcceptableTemplateNames(Result)) { + hasAnyAcceptableTemplateNames(Result, /*AllowFunctionTemplates=*/true, + /*AllowDependent=*/false)) { // C++ [temp.local]p3: // A lookup that finds an injected-class-name (10.2) can result in an // ambiguity in certain cases (for example, if it is found in more than @@ -1041,7 +1042,9 @@ Corrected: } if (getLangOpts().CPlusPlus && NextToken.is(tok::less) && - (IsFilteredTemplateName || hasAnyAcceptableTemplateNames(Result))) { + (IsFilteredTemplateName || + hasAnyAcceptableTemplateNames(Result, /*AllowFunctionTemplates=*/true, + /*AllowDependent=*/false))) { // C++ [temp.names]p3: // After name lookup (3.4) finds that a name is a template-name or that // an operator-function-id or a literal- operator-id refers to a set of @@ -1060,15 +1063,16 @@ Corrected: Template = Context.getOverloadedTemplateName(Result.begin(), Result.end()); } else { - TemplateDecl *TD - = cast<TemplateDecl>((*Result.begin())->getUnderlyingDecl()); + auto *TD = cast<TemplateDecl>(getAsTemplateNameDecl( + *Result.begin(), /*AllowFunctionTemplates=*/true, + /*AllowDependent=*/false)); IsFunctionTemplate = isa<FunctionTemplateDecl>(TD); IsVarTemplate = isa<VarTemplateDecl>(TD); if (SS.isSet() && !SS.isInvalid()) - Template = Context.getQualifiedTemplateName(SS.getScopeRep(), - /*TemplateKeyword=*/false, - TD); + Template = + Context.getQualifiedTemplateName(SS.getScopeRep(), + /*TemplateKeyword=*/false, TD); else Template = TemplateName(TD); } |