@@ -7347,6 +7347,9 @@ ExprResult Sema::CheckTemplateArgument(NamedDecl *Param, QualType ParamType,
73477347 return Arg;
73487348 }
73497349
7350+ // These should have all been handled above using the C++17 rules.
7351+ assert (!ArgPE && !StrictCheck);
7352+
73507353 // C++ [temp.arg.nontype]p5:
73517354 // The following conversions are performed on each expression used
73527355 // as a non-type template-argument. If a non-type
@@ -7374,13 +7377,13 @@ ExprResult Sema::CheckTemplateArgument(NamedDecl *Param, QualType ParamType,
73747377 // template-parameter; or
73757378 llvm::APSInt Value;
73767379 ExprResult ArgResult = CheckConvertedConstantExpression (
7377- DeductionArg , ParamType, Value, CCEKind::TemplateArg);
7380+ Arg , ParamType, Value, CCEKind::TemplateArg);
73787381 if (ArgResult.isInvalid ())
73797382 return ExprError ();
7380- setDeductionArg ( ArgResult.get () );
7383+ Arg = ArgResult.get ();
73817384
73827385 // We can't check arbitrary value-dependent arguments.
7383- if (DeductionArg ->isValueDependent ()) {
7386+ if (Arg ->isValueDependent ()) {
73847387 SugaredConverted = TemplateArgument (Arg, /* IsCanonical=*/ false );
73857388 CanonicalConverted =
73867389 Context.getCanonicalTemplateArgument (SugaredConverted);
@@ -7397,24 +7400,18 @@ ExprResult Sema::CheckTemplateArgument(NamedDecl *Param, QualType ParamType,
73977400 ? Context.getIntWidth (IntegerType)
73987401 : Context.getTypeSize (IntegerType));
73997402
7400- if (ArgPE) {
7401- SugaredConverted = TemplateArgument (Arg, /* IsCanonical=*/ false );
7402- CanonicalConverted =
7403- Context.getCanonicalTemplateArgument (SugaredConverted);
7404- } else {
7405- SugaredConverted = TemplateArgument (Context, Value, ParamType);
7406- CanonicalConverted = TemplateArgument (
7407- Context, Value, Context.getCanonicalType (ParamType));
7408- }
7403+ SugaredConverted = TemplateArgument (Context, Value, ParamType);
7404+ CanonicalConverted =
7405+ TemplateArgument (Context, Value, Context.getCanonicalType (ParamType));
74097406 return Arg;
74107407 }
74117408
74127409 ExprResult ArgResult = DefaultLvalueConversion (Arg);
74137410 if (ArgResult.isInvalid ())
74147411 return ExprError ();
7415- DeductionArg = ArgResult.get ();
7412+ Arg = ArgResult.get ();
74167413
7417- QualType ArgType = DeductionArg ->getType ();
7414+ QualType ArgType = Arg ->getType ();
74187415
74197416 // C++ [temp.arg.nontype]p1:
74207417 // A template-argument for a non-type, non-template
@@ -7425,11 +7422,12 @@ ExprResult Sema::CheckTemplateArgument(NamedDecl *Param, QualType ParamType,
74257422 // -- the name of a non-type template-parameter; or
74267423 llvm::APSInt Value;
74277424 if (!ArgType->isIntegralOrEnumerationType ()) {
7428- Diag (StartLoc , diag::err_template_arg_not_integral_or_enumeral)
7429- << ArgType << DeductionArg ->getSourceRange ();
7425+ Diag (Arg-> getBeginLoc () , diag::err_template_arg_not_integral_or_enumeral)
7426+ << ArgType << Arg ->getSourceRange ();
74307427 NoteTemplateParameterLocation (*Param);
74317428 return ExprError ();
7432- } else if (!DeductionArg->isValueDependent ()) {
7429+ }
7430+ if (!Arg->isValueDependent ()) {
74337431 class TmplArgICEDiagnoser : public VerifyICEDiagnoser {
74347432 QualType T;
74357433
@@ -7442,10 +7440,8 @@ ExprResult Sema::CheckTemplateArgument(NamedDecl *Param, QualType ParamType,
74427440 }
74437441 } Diagnoser (ArgType);
74447442
7445- DeductionArg =
7446- VerifyIntegerConstantExpression (DeductionArg, &Value, Diagnoser)
7447- .get ();
7448- if (!DeductionArg)
7443+ Arg = VerifyIntegerConstantExpression (Arg, &Value, Diagnoser).get ();
7444+ if (!Arg)
74497445 return ExprError ();
74507446 }
74517447
@@ -7458,28 +7454,23 @@ ExprResult Sema::CheckTemplateArgument(NamedDecl *Param, QualType ParamType,
74587454 // Okay: no conversion necessary
74597455 } else if (ParamType->isBooleanType ()) {
74607456 // This is an integral-to-boolean conversion.
7461- DeductionArg =
7462- ImpCastExprToType (DeductionArg, ParamType, CK_IntegralToBoolean)
7463- .get ();
7457+ Arg = ImpCastExprToType (Arg, ParamType, CK_IntegralToBoolean).get ();
74647458 } else if (IsIntegralPromotion (Arg, ArgType, ParamType) ||
74657459 !ParamType->isEnumeralType ()) {
74667460 // This is an integral promotion or conversion.
7467- DeductionArg =
7468- ImpCastExprToType (DeductionArg, ParamType, CK_IntegralCast).get ();
7461+ Arg = ImpCastExprToType (Arg, ParamType, CK_IntegralCast).get ();
74697462 } else {
74707463 // We can't perform this conversion.
74717464 Diag (StartLoc, diag::err_template_arg_not_convertible)
7472- << DeductionArg->getType () << ParamType
7473- << DeductionArg->getSourceRange ();
7465+ << Arg->getType () << ParamType << Arg->getSourceRange ();
74747466 NoteTemplateParameterLocation (*Param);
74757467 return ExprError ();
74767468 }
7477- setDeductionArg (DeductionArg);
74787469
74797470 // Add the value of this argument to the list of converted
74807471 // arguments. We use the bitwidth and signedness of the template
74817472 // parameter.
7482- if (DeductionArg ->isValueDependent ()) {
7473+ if (Arg ->isValueDependent ()) {
74837474 // The argument is value-dependent. Create a new
74847475 // TemplateArgument with the converted expression.
74857476 SugaredConverted = TemplateArgument (Arg, /* IsCanonical=*/ false );
@@ -7537,20 +7528,14 @@ ExprResult Sema::CheckTemplateArgument(NamedDecl *Param, QualType ParamType,
75377528 }
75387529 }
75397530
7540- if (ArgPE) {
7541- SugaredConverted = TemplateArgument (Arg, /* IsCanonical=*/ false );
7542- CanonicalConverted =
7543- Context.getCanonicalTemplateArgument (SugaredConverted);
7544- } else {
7545- QualType T = ParamType->isEnumeralType () ? ParamType : IntegerType;
7546- SugaredConverted = TemplateArgument (Context, Value, T);
7547- CanonicalConverted =
7548- TemplateArgument (Context, Value, Context.getCanonicalType (T));
7549- }
7531+ QualType T = ParamType->isEnumeralType () ? ParamType : IntegerType;
7532+ SugaredConverted = TemplateArgument (Context, Value, T);
7533+ CanonicalConverted =
7534+ TemplateArgument (Context, Value, Context.getCanonicalType (T));
75507535 return Arg;
75517536 }
75527537
7553- QualType ArgType = DeductionArg ->getType ();
7538+ QualType ArgType = Arg ->getType ();
75547539 DeclAccessPair FoundResult; // temporary for ResolveOverloadedFunction
75557540
75567541 // Handle pointer-to-function, reference-to-function, and
@@ -7577,7 +7562,7 @@ ExprResult Sema::CheckTemplateArgument(NamedDecl *Param, QualType ParamType,
75777562 ParamType->castAs <MemberPointerType>()->getPointeeType ()
75787563 ->isFunctionType ())) {
75797564
7580- if (DeductionArg ->getType () == Context.OverloadTy ) {
7565+ if (Arg ->getType () == Context.OverloadTy ) {
75817566 if (FunctionDecl *Fn = ResolveAddressOfOverloadedFunction (Arg, ParamType,
75827567 true ,
75837568 FoundResult)) {
@@ -7587,12 +7572,11 @@ ExprResult Sema::CheckTemplateArgument(NamedDecl *Param, QualType ParamType,
75877572 ExprResult Res = FixOverloadedFunctionReference (Arg, FoundResult, Fn);
75887573 if (Res.isInvalid ())
75897574 return ExprError ();
7590- DeductionArg = Res.get ();
7575+ Arg = Res.get ();
75917576 ArgType = Arg->getType ();
75927577 } else
75937578 return ExprError ();
75947579 }
7595- setDeductionArg (DeductionArg);
75967580
75977581 if (!ParamType->isMemberPointerType ()) {
75987582 if (CheckTemplateArgumentAddressOfObjectOrFunction (
@@ -7608,8 +7592,6 @@ ExprResult Sema::CheckTemplateArgument(NamedDecl *Param, QualType ParamType,
76087592 return Arg;
76097593 }
76107594
7611- setDeductionArg (DeductionArg);
7612-
76137595 if (ParamType->isPointerType ()) {
76147596 // -- for a non-type template-parameter of type pointer to
76157597 // object, qualification conversions (4.4) and the
@@ -7618,7 +7600,6 @@ ExprResult Sema::CheckTemplateArgument(NamedDecl *Param, QualType ParamType,
76187600 assert (ParamType->getPointeeType ()->isIncompleteOrObjectType () &&
76197601 " Only object pointers allowed here" );
76207602
7621- // FIXME: Deal with pack expansions here.
76227603 if (CheckTemplateArgumentAddressOfObjectOrFunction (
76237604 *this , Param, ParamType, Arg, SugaredConverted, CanonicalConverted))
76247605 return ExprError ();
@@ -7635,7 +7616,6 @@ ExprResult Sema::CheckTemplateArgument(NamedDecl *Param, QualType ParamType,
76357616 assert (ParamRefType->getPointeeType ()->isIncompleteOrObjectType () &&
76367617 " Only object references allowed here" );
76377618
7638- // FIXME: Deal with pack expansions here.
76397619 if (Arg->getType () == Context.OverloadTy ) {
76407620 if (FunctionDecl *Fn = ResolveAddressOfOverloadedFunction (Arg,
76417621 ParamRefType->getPointeeType (),
@@ -7660,18 +7640,17 @@ ExprResult Sema::CheckTemplateArgument(NamedDecl *Param, QualType ParamType,
76607640
76617641 // Deal with parameters of type std::nullptr_t.
76627642 if (ParamType->isNullPtrType ()) {
7663- if (DeductionArg ->isTypeDependent () || DeductionArg ->isValueDependent ()) {
7643+ if (Arg ->isTypeDependent () || Arg ->isValueDependent ()) {
76647644 SugaredConverted = TemplateArgument (Arg, /* IsCanonical=*/ false );
76657645 CanonicalConverted =
76667646 Context.getCanonicalTemplateArgument (SugaredConverted);
76677647 return Arg;
76687648 }
76697649
7670- switch (isNullPointerValueTemplateArgument (*this , Param, ParamType,
7671- DeductionArg)) {
7650+ switch (isNullPointerValueTemplateArgument (*this , Param, ParamType, Arg)) {
76727651 case NPV_NotNullPointer:
76737652 Diag (Arg->getExprLoc (), diag::err_template_arg_not_convertible)
7674- << DeductionArg ->getType () << ParamType;
7653+ << Arg ->getType () << ParamType;
76757654 NoteTemplateParameterLocation (*Param);
76767655 return ExprError ();
76777656
@@ -7680,17 +7659,10 @@ ExprResult Sema::CheckTemplateArgument(NamedDecl *Param, QualType ParamType,
76807659
76817660 case NPV_NullPointer:
76827661 Diag (Arg->getExprLoc (), diag::warn_cxx98_compat_template_arg_null);
7683- if (ArgPE) {
7684- SugaredConverted = TemplateArgument (Arg, /* IsCanonical=*/ false );
7685- CanonicalConverted =
7686- Context.getCanonicalTemplateArgument (SugaredConverted);
7687- } else {
7688- SugaredConverted = TemplateArgument (ParamType,
7662+ SugaredConverted = TemplateArgument (ParamType,
7663+ /* isNullPtr=*/ true );
7664+ CanonicalConverted = TemplateArgument (Context.getCanonicalType (ParamType),
76897665 /* isNullPtr=*/ true );
7690- CanonicalConverted =
7691- TemplateArgument (Context.getCanonicalType (ParamType),
7692- /* isNullPtr=*/ true );
7693- }
76947666 return Arg;
76957667 }
76967668 }
@@ -7699,7 +7671,6 @@ ExprResult Sema::CheckTemplateArgument(NamedDecl *Param, QualType ParamType,
76997671 // member, qualification conversions (4.4) are applied.
77007672 assert (ParamType->isMemberPointerType () && " Only pointers to members remain" );
77017673
7702- // FIXME: Deal with pack expansions here.
77037674 if (CheckTemplateArgumentPointerToMember (
77047675 *this , Param, ParamType, Arg, SugaredConverted, CanonicalConverted))
77057676 return ExprError ();
0 commit comments