Hi,<br><br>without the following patch, clang incorrectly claims<br>that, for example, -128 does not fit in a signed char<br>when used as a template argument.<br><br>I found this when trying to use clang++ to parse a boost header <br>
file. <br><br>I hope that you find it useful.<br><br>Kind regards,<br>Maurice<br><br><br>diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp<br>index e6bd77d..2e260e0 100644<br>--- a/lib/Sema/SemaTemplate.cpp<br>
+++ b/lib/Sema/SemaTemplate.cpp<br>@@ -2489,12 +2489,24 @@ bool Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param,<br> // Check that we don't overflow the template parameter type.<br> unsigned AllowedBits = Context.getTypeSize(IntegerType);<br>
if (Value.getActiveBits() > AllowedBits) {<br>- Diag(Arg->getSourceRange().getBegin(),<br>- diag::err_template_arg_too_large)<br>+ bool ConstantFits = false;<br>+<br>+ if (IntegerType->isSignedIntegerType()) {<br>
+ llvm::APSInt TmpValue = Value;<br>+ TmpValue.extOrTrunc(AllowedBits);<br>+<br>+ if (TmpValue.isMinSignedValue())<br>+ ConstantFits = true;<br>+ }<br>+<br>+ if (!ConstantFits) {<br>
+ Diag(Arg->getSourceRange().getBegin(),<br>+ diag::err_template_arg_too_large)<br> << Value.toString(10) << Param->getType()<br> << Arg->getSourceRange();<br>
- Diag(Param->getLocation(), diag::note_template_param_here);<br>- return true;<br>+ Diag(Param->getLocation(), diag::note_template_param_here);<br>+ return true;<br>+ } <br>
}<br> <br> if (Value.getBitWidth() != AllowedBits)<br><br>