Skip to content

Commit 09539af

Browse files
committed
[clang] simplify constant template parameter type deduction for partial ordering
This simplifies things a little bit. This is mostly NFCish, except the reference type deduction workaround now applies in partial ordering as well, but we don't have any test cases and any reason to suspect this is significant.
1 parent b5daf76 commit 09539af

File tree

1 file changed

+5
-17
lines changed

1 file changed

+5
-17
lines changed

clang/lib/Sema/SemaTemplateDeduction.cpp

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ DeduceNonTypeTemplateArgument(Sema &S, TemplateParameterList *TemplateParams,
483483
return TemplateDeductionResult::Inconsistent;
484484
}
485485
Deduced[NTTP.getIndex()] = Result;
486-
if (!S.getLangOpts().CPlusPlus17)
486+
if (!S.getLangOpts().CPlusPlus17 && !PartialOrdering)
487487
return TemplateDeductionResult::Success;
488488

489489
if (NTTP.isExpandedParameterPack())
@@ -2653,23 +2653,11 @@ DeduceTemplateArguments(Sema &S, TemplateParameterList *TemplateParams,
26532653
switch (A.getKind()) {
26542654
case TemplateArgument::Expression: {
26552655
const Expr *E = A.getAsExpr();
2656-
// When checking NTTP, if either the parameter or the argument is
2657-
// dependent, as there would be otherwise nothing to deduce, we force
2658-
// the argument to the parameter type using this dependent implicit
2659-
// cast, in order to maintain invariants. Now we can deduce the
2660-
// resulting type from the original type, and deduce the original type
2661-
// against the parameter we are checking.
2662-
if (const auto *ICE = dyn_cast<ImplicitCastExpr>(E);
2663-
ICE && ICE->getCastKind() == clang::CK_Dependent) {
2656+
// The type of the value is the type of the expression before any
2657+
// implicit conversions.
2658+
if (const auto *ICE = dyn_cast<ImplicitCastExpr>(E)) {
26642659
E = ICE->getSubExpr();
2665-
if (auto Result = DeduceTemplateArgumentsByTypeMatch(
2666-
S, TemplateParams, ICE->getType(), E->getType(), Info,
2667-
Deduced, TDF_SkipNonDependent,
2668-
PartialOrdering ? PartialOrderingKind::NonCall
2669-
: PartialOrderingKind::None,
2670-
/*DeducedFromArrayBound=*/false, HasDeducedAnyParam);
2671-
Result != TemplateDeductionResult::Success)
2672-
return Result;
2660+
assert(!isa<ImplicitCastExpr>(E));
26732661
}
26742662
return DeduceNonTypeTemplateArgument(
26752663
S, TemplateParams, NTTP, DeducedTemplateArgument(A), E->getType(),

0 commit comments

Comments
 (0)