diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2016-09-28 23:55:27 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2016-09-28 23:55:27 +0000 |
commit | 5f274389d1d99b32c81773aa8357f274ba15dc85 (patch) | |
tree | ab6dc1a8cffeed6c11a8a3493a3c599f21996290 /clang/lib/Sema/SemaTemplate.cpp | |
parent | dc8a254663d17a2122547320ca4b4f7dcf51e360 (diff) | |
download | bcm5719-llvm-5f274389d1d99b32c81773aa8357f274ba15dc85.tar.gz bcm5719-llvm-5f274389d1d99b32c81773aa8357f274ba15dc85.zip |
P0127R2: Support type deduction for types of non-type template parameters in
C++1z.
Patch by James Touton! Some bugfixes and rebasing by me.
llvm-svn: 282651
Diffstat (limited to 'clang/lib/Sema/SemaTemplate.cpp')
-rw-r--r-- | clang/lib/Sema/SemaTemplate.cpp | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index bef36206e09..b1bb97b7586 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -730,7 +730,13 @@ Sema::CheckNonTypeTemplateParameterType(QualType T, SourceLocation Loc) { T->isNullPtrType() || // If T is a dependent type, we can't do the check now, so we // assume that it is well-formed. - T->isDependentType()) { + T->isDependentType() || + // Allow use of auto in template parameter declarations. + T->isUndeducedType()) { + if (T->isUndeducedType()) { + Diag(Loc, diag::warn_cxx14_compat_template_nontype_parm_auto_type) + << QualType(T->getContainedAutoType(), 0); + } // C++ [temp.param]p5: The top-level cv-qualifiers on the template-parameter // are ignored when determining its type. return T.getUnqualifiedType(); @@ -4975,6 +4981,29 @@ ExprResult Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param, CheckTemplateArgumentKind CTAK) { SourceLocation StartLoc = Arg->getLocStart(); + // If the parameter type somehow involves auto, deduce the type now. + if (getLangOpts().CPlusPlus1z && ParamType->isUndeducedType()) { + if (DeduceAutoType( + Context.getTrivialTypeSourceInfo(ParamType, Param->getLocation()), + Arg, ParamType) == DAR_Failed) { + Diag(Arg->getExprLoc(), + diag::err_non_type_template_parm_type_deduction_failure) + << Param->getDeclName() << Param->getType() << Arg->getType() + << Arg->getSourceRange(); + Diag(Param->getLocation(), diag::note_template_param_here); + return ExprError(); + } + // CheckNonTypeTemplateParameterType will produce a diagnostic if there's + // an error. The error message normally references the parameter + // declaration, but here we'll pass the argument location because that's + // where the parameter type is deduced. + ParamType = CheckNonTypeTemplateParameterType(ParamType, Arg->getExprLoc()); + if (ParamType.isNull()) { + Diag(Param->getLocation(), diag::note_template_param_here); + return ExprError(); + } + } + // If either the parameter has a dependent type or the argument is // type-dependent, there's nothing we can check now. if (ParamType->isDependentType() || Arg->isTypeDependent()) { @@ -7255,7 +7284,7 @@ Sema::CheckMemberSpecialization(NamedDecl *Member, LookupResult &Previous) { if (InstantiationFunction->isDeleted()) { assert(InstantiationFunction->getCanonicalDecl() == InstantiationFunction); - InstantiationFunction->setDeletedAsWritten(false);
+ InstantiationFunction->setDeletedAsWritten(false); } } |