@@ -3501,29 +3501,46 @@ ExprResult Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
3501
3501
return ExprError ();
3502
3502
}
3503
3503
3504
+ // Add the value of this argument to the list of converted
3505
+ // arguments. We use the bitwidth and signedness of the template
3506
+ // parameter.
3507
+ if (Arg->isValueDependent ()) {
3508
+ // The argument is value-dependent. Create a new
3509
+ // TemplateArgument with the converted expression.
3510
+ Converted = TemplateArgument (Arg);
3511
+ return Owned (Arg);
3512
+ }
3513
+
3504
3514
QualType IntegerType = Context.getCanonicalType (ParamType);
3505
3515
if (const EnumType *Enum = IntegerType->getAs <EnumType>())
3506
3516
IntegerType = Context.getCanonicalType (Enum->getDecl ()->getIntegerType ());
3507
3517
3508
- if (!Arg->isValueDependent ()) {
3518
+ if (ParamType->isBooleanType ()) {
3519
+ // Value must be zero or one.
3520
+ Value = Value != 0 ;
3521
+ unsigned AllowedBits = Context.getTypeSize (IntegerType);
3522
+ if (Value.getBitWidth () != AllowedBits)
3523
+ Value = Value.extOrTrunc (AllowedBits);
3524
+ Value.setIsSigned (IntegerType->isSignedIntegerType ());
3525
+ } else {
3509
3526
llvm::APSInt OldValue = Value;
3510
-
3527
+
3511
3528
// Coerce the template argument's value to the value it will have
3512
3529
// based on the template parameter's type.
3513
3530
unsigned AllowedBits = Context.getTypeSize (IntegerType);
3514
3531
if (Value.getBitWidth () != AllowedBits)
3515
3532
Value = Value.extOrTrunc (AllowedBits);
3516
3533
Value.setIsSigned (IntegerType->isSignedIntegerType ());
3517
-
3534
+
3518
3535
// Complain if an unsigned parameter received a negative value.
3519
3536
if (IntegerType->isUnsignedIntegerType ()
3520
- && (OldValue.isSigned () && OldValue.isNegative ())) {
3537
+ && (OldValue.isSigned () && OldValue.isNegative ())) {
3521
3538
Diag (Arg->getSourceRange ().getBegin (), diag::warn_template_arg_negative)
3522
3539
<< OldValue.toString (10 ) << Value.toString (10 ) << Param->getType ()
3523
3540
<< Arg->getSourceRange ();
3524
3541
Diag (Param->getLocation (), diag::note_template_param_here);
3525
3542
}
3526
-
3543
+
3527
3544
// Complain if we overflowed the template parameter's type.
3528
3545
unsigned RequiredBits;
3529
3546
if (IntegerType->isUnsignedIntegerType ())
@@ -3541,16 +3558,6 @@ ExprResult Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
3541
3558
}
3542
3559
}
3543
3560
3544
- // Add the value of this argument to the list of converted
3545
- // arguments. We use the bitwidth and signedness of the template
3546
- // parameter.
3547
- if (Arg->isValueDependent ()) {
3548
- // The argument is value-dependent. Create a new
3549
- // TemplateArgument with the converted expression.
3550
- Converted = TemplateArgument (Arg);
3551
- return Owned (Arg);
3552
- }
3553
-
3554
3561
Converted = TemplateArgument (Value,
3555
3562
ParamType->isEnumeralType () ? ParamType
3556
3563
: IntegerType);
0 commit comments