@@ -7068,22 +7068,8 @@ ExprResult Sema::CheckTemplateArgument(NamedDecl *Param, QualType ParamType,
7068
7068
7069
7069
// If the parameter type somehow involves auto, deduce the type now.
7070
7070
DeducedType *DeducedT = ParamType->getContainedDeducedType ();
7071
- if (getLangOpts ().CPlusPlus17 && DeducedT && !DeducedT->isDeduced ()) {
7072
- // During template argument deduction, we allow 'decltype(auto)' to
7073
- // match an arbitrary dependent argument.
7074
- // FIXME: The language rules don't say what happens in this case.
7075
- // FIXME: We get an opaque dependent type out of decltype(auto) if the
7076
- // expression is merely instantiation-dependent; is this enough?
7077
- if (DeductionArg->isTypeDependent ()) {
7078
- auto *AT = dyn_cast<AutoType>(DeducedT);
7079
- if (AT && AT->isDecltypeAuto ()) {
7080
- SugaredConverted = TemplateArgument (Arg, /* IsCanonical=*/ false );
7081
- CanonicalConverted = TemplateArgument (
7082
- Context.getCanonicalTemplateArgument (SugaredConverted));
7083
- return Arg;
7084
- }
7085
- }
7086
-
7071
+ bool IsDeduced = DeducedT && !DeducedT->isDeduced ();
7072
+ if (IsDeduced) {
7087
7073
// When checking a deduced template argument, deduce from its type even if
7088
7074
// the type is dependent, in order to check the types of non-type template
7089
7075
// arguments line up properly in partial ordering.
@@ -7112,17 +7098,21 @@ ExprResult Sema::CheckTemplateArgument(NamedDecl *Param, QualType ParamType,
7112
7098
// along with the other associated constraints after
7113
7099
// checking the template argument list.
7114
7100
/* IgnoreConstraints=*/ true );
7115
- if (Result == TemplateDeductionResult::AlreadyDiagnosed) {
7116
- return ExprError ();
7117
- } else if (Result != TemplateDeductionResult::Success) {
7118
- if (const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param)) {
7119
- Diag (Arg->getExprLoc (),
7120
- diag::err_non_type_template_parm_type_deduction_failure)
7121
- << Param->getDeclName () << NTTP->getType () << Arg->getType ()
7122
- << Arg->getSourceRange ();
7101
+ if (Result != TemplateDeductionResult::Success) {
7102
+ ParamType = TSI->getType ();
7103
+ if (StrictCheck || !DeductionArg->isTypeDependent ()) {
7104
+ if (Result == TemplateDeductionResult::AlreadyDiagnosed)
7105
+ return ExprError ();
7106
+ if (const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param))
7107
+ Diag (Arg->getExprLoc (),
7108
+ diag::err_non_type_template_parm_type_deduction_failure)
7109
+ << Param->getDeclName () << NTTP->getType () << Arg->getType ()
7110
+ << Arg->getSourceRange ();
7111
+ NoteTemplateParameterLocation (*Param);
7112
+ return ExprError ();
7123
7113
}
7124
- NoteTemplateParameterLocation (*Param );
7125
- return ExprError ( );
7114
+ ParamType = SubstAutoTypeDependent (ParamType );
7115
+ assert (!ParamType. isNull () && " substituting DependentTy can't fail " );
7126
7116
}
7127
7117
}
7128
7118
// CheckNonTypeTemplateParameterType will produce a diagnostic if there's
@@ -7144,14 +7134,16 @@ ExprResult Sema::CheckTemplateArgument(NamedDecl *Param, QualType ParamType,
7144
7134
// type-dependent, there's nothing we can check now.
7145
7135
if (ParamType->isDependentType () || DeductionArg->isTypeDependent ()) {
7146
7136
// Force the argument to the type of the parameter to maintain invariants.
7147
- ExprResult E = ImpCastExprToType (
7148
- DeductionArg, ParamType.getNonLValueExprType (Context), CK_Dependent,
7149
- ParamType->isLValueReferenceType () ? VK_LValue
7150
- : ParamType->isRValueReferenceType () ? VK_XValue
7151
- : VK_PRValue);
7152
- if (E.isInvalid ())
7153
- return ExprError ();
7154
- setDeductionArg (E.get ());
7137
+ if (!IsDeduced) {
7138
+ ExprResult E = ImpCastExprToType (
7139
+ DeductionArg, ParamType.getNonLValueExprType (Context), CK_Dependent,
7140
+ ParamType->isLValueReferenceType () ? VK_LValue
7141
+ : ParamType->isRValueReferenceType () ? VK_XValue
7142
+ : VK_PRValue);
7143
+ if (E.isInvalid ())
7144
+ return ExprError ();
7145
+ setDeductionArg (E.get ());
7146
+ }
7155
7147
SugaredConverted = TemplateArgument (Arg, /* IsCanonical=*/ false );
7156
7148
CanonicalConverted = TemplateArgument (
7157
7149
Context.getCanonicalTemplateArgument (SugaredConverted));
@@ -8555,6 +8547,7 @@ static SourceRange findTemplateParameter(unsigned Depth, TypeLoc TL) {
8555
8547
static bool CheckNonTypeTemplatePartialSpecializationArgs (
8556
8548
Sema &S, SourceLocation TemplateNameLoc, NonTypeTemplateParmDecl *Param,
8557
8549
const TemplateArgument *Args, unsigned NumArgs, bool IsDefaultArgument) {
8550
+ bool HasError = false ;
8558
8551
for (unsigned I = 0 ; I != NumArgs; ++I) {
8559
8552
if (Args[I].getKind () == TemplateArgument::Pack) {
8560
8553
if (CheckNonTypeTemplatePartialSpecializationArgs (
@@ -8569,6 +8562,10 @@ static bool CheckNonTypeTemplatePartialSpecializationArgs(
8569
8562
continue ;
8570
8563
8571
8564
Expr *ArgExpr = Args[I].getAsExpr ();
8565
+ if (ArgExpr->containsErrors ()) {
8566
+ HasError = true ;
8567
+ continue ;
8568
+ }
8572
8569
8573
8570
// We can have a pack expansion of any of the bullets below.
8574
8571
if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(ArgExpr))
@@ -8638,7 +8635,7 @@ static bool CheckNonTypeTemplatePartialSpecializationArgs(
8638
8635
}
8639
8636
}
8640
8637
8641
- return false ;
8638
+ return HasError ;
8642
8639
}
8643
8640
8644
8641
bool Sema::CheckTemplatePartialSpecializationArgs (
0 commit comments