diff options
| author | Richard Smith <richard-llvm@metafoo.co.uk> | 2016-12-27 02:02:09 +0000 |
|---|---|---|
| committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2016-12-27 02:02:09 +0000 |
| commit | 01bfa68fecaf53e5d9b6e7852b7264cdc5c21210 (patch) | |
| tree | 0ece6be53f5f1ca526ab820ba7a917d21d70ce81 /clang/lib/Sema/SemaTemplate.cpp | |
| parent | 7f8540b5e7d1dd83879bedb544b91715d544dd18 (diff) | |
| download | bcm5719-llvm-01bfa68fecaf53e5d9b6e7852b7264cdc5c21210.tar.gz bcm5719-llvm-01bfa68fecaf53e5d9b6e7852b7264cdc5c21210.zip | |
Check and build conversion sequences for non-type template arguments in
dependent contexts when processing the template in C++11 and C++14, just like
we do in C++98 and C++1z. This allows us to diagnose invalid templates earlier.
llvm-svn: 290567
Diffstat (limited to 'clang/lib/Sema/SemaTemplate.cpp')
| -rw-r--r-- | clang/lib/Sema/SemaTemplate.cpp | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index 87667f27ea9..83146afd022 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -5076,8 +5076,8 @@ ExprResult Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param, // For a value-dependent argument, CheckConvertedConstantExpression is // permitted (and expected) to be unable to determine a value. if (ArgResult.get()->isValueDependent()) { - Converted = TemplateArgument(Arg); - return Arg; + Converted = TemplateArgument(ArgResult.get()); + return ArgResult; } QualType CanonParamType = Context.getCanonicalType(ParamType); @@ -5184,14 +5184,6 @@ ExprResult Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param, // conversions (4.7) are applied. if (getLangOpts().CPlusPlus11) { - // We can't check arbitrary value-dependent arguments. - // FIXME: If there's no viable conversion to the template parameter type, - // we should be able to diagnose that prior to instantiation. - if (Arg->isValueDependent()) { - Converted = TemplateArgument(Arg); - return Arg; - } - // C++ [temp.arg.nontype]p1: // A template-argument for a non-type, non-template template-parameter // shall be one of: @@ -5206,6 +5198,12 @@ ExprResult Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param, if (ArgResult.isInvalid()) return ExprError(); + // We can't check arbitrary value-dependent arguments. + if (ArgResult.get()->isValueDependent()) { + Converted = TemplateArgument(ArgResult.get()); + return ArgResult; + } + // Widen the argument value to sizeof(parameter type). This is almost // always a no-op, except when the parameter type is bool. In // that case, this may extend the argument from 1 bit to 8 bits. |

