Attempt to fix incorrect diagnoses of diag::err_template_arg_too_large

Hi,

without the following patch, clang incorrectly claims
that, for example, -128 does not fit in a signed char
when used as a template argument.

I found this when trying to use clang++ to parse a boost header
file.

I hope that you find it useful.

Kind regards,
Maurice

diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp
index e6bd77d…2e260e0 100644
— a/lib/Sema/SemaTemplate.cpp
+++ b/lib/Sema/SemaTemplate.cpp
@@ -2489,12 +2489,24 @@ bool Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
// Check that we don’t overflow the template parameter type.
unsigned AllowedBits = Context.getTypeSize(IntegerType);
if (Value.getActiveBits() > AllowedBits) {

  • Diag(Arg->getSourceRange().getBegin(),
  • diag::err_template_arg_too_large)
  • bool ConstantFits = false;

Interesting bug report, but the patch doesn't look right; I'll take a look.

-Eli