diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2010-01-31 10:01:20 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2010-01-31 10:01:20 +0000 |
commit | 038cc399940deefc0f55aad8be97312a7390e2ad (patch) | |
tree | 2b0474358c2757d2de936e38d346c4d9d146e17f /lib/Sema/SemaTemplate.cpp | |
parent | 9db7dbb918ca49f4ee6c181e4917e7b6ec547353 (diff) |
Fix PR6159 and several other problems with value-dependent non-type template
arguments. This both prevents meaningless checks on these arguments and ensures
that they are represented as an expression by the instantiation.
Cleaned up and added standard text to the relevant test case. Also started
adding tests for *rejected* cases. At least one FIXME here where (I think) we
allow something we shouldn't. More to come in the area of rejecting crazy
arguments with decent diagnostics. Suggestions welcome for still better
diagnostics on these errors!
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94953 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaTemplate.cpp')
-rw-r--r-- | lib/Sema/SemaTemplate.cpp | 40 |
1 files changed, 31 insertions, 9 deletions
diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp index f660b3c2ee..44b0d83b46 100644 --- a/lib/Sema/SemaTemplate.cpp +++ b/lib/Sema/SemaTemplate.cpp @@ -2307,7 +2307,17 @@ bool Sema::CheckTemplateArgumentAddressOfObjectOrFunction(Expr *Arg, } else DRE = dyn_cast<DeclRefExpr>(Arg); - if (!DRE || !isa<ValueDecl>(DRE->getDecl())) + if (!DRE) + return Diag(Arg->getSourceRange().getBegin(), + diag::err_template_arg_not_decl_ref) + << Arg->getSourceRange(); + + // Stop checking the precise nature of the argument if it is value dependent, + // it should be checked when instantiated. + if (Arg->isValueDependent()) + return false; + + if (!isa<ValueDecl>(DRE->getDecl())) return Diag(Arg->getSourceRange().getBegin(), diag::err_template_arg_not_object_or_func_form) << Arg->getSourceRange(); @@ -2658,9 +2668,13 @@ bool Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param, if (CheckTemplateArgumentAddressOfObjectOrFunction(Arg, Entity)) return true; - if (Entity) - Entity = cast<NamedDecl>(Entity->getCanonicalDecl()); - Converted = TemplateArgument(Entity); + if (Arg->isValueDependent()) { + Converted = TemplateArgument(Arg); + } else { + if (Entity) + Entity = cast<NamedDecl>(Entity->getCanonicalDecl()); + Converted = TemplateArgument(Entity); + } return false; } @@ -2698,9 +2712,13 @@ bool Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param, if (CheckTemplateArgumentAddressOfObjectOrFunction(Arg, Entity)) return true; - if (Entity) - Entity = cast<NamedDecl>(Entity->getCanonicalDecl()); - Converted = TemplateArgument(Entity); + if (Arg->isValueDependent()) { + Converted = TemplateArgument(Arg); + } else { + if (Entity) + Entity = cast<NamedDecl>(Entity->getCanonicalDecl()); + Converted = TemplateArgument(Entity); + } return false; } @@ -2740,8 +2758,12 @@ bool Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param, if (CheckTemplateArgumentAddressOfObjectOrFunction(Arg, Entity)) return true; - Entity = cast<NamedDecl>(Entity->getCanonicalDecl()); - Converted = TemplateArgument(Entity); + if (Arg->isValueDependent()) { + Converted = TemplateArgument(Arg); + } else { + Entity = cast<NamedDecl>(Entity->getCanonicalDecl()); + Converted = TemplateArgument(Entity); + } return false; } |