[clang] 7b28fcd - [clang] simplify constant template parameter type deduction for partial ordering (#160433)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 25 12:49:25 PDT 2025
Author: Matheus Izvekov
Date: 2025-09-25T16:49:21-03:00
New Revision: 7b28fcd2b182ba2c9d2d71c386be92fc0ee3cc9d
URL: https://github.com/llvm/llvm-project/commit/7b28fcd2b182ba2c9d2d71c386be92fc0ee3cc9d
DIFF: https://github.com/llvm/llvm-project/commit/7b28fcd2b182ba2c9d2d71c386be92fc0ee3cc9d.diff
LOG: [clang] simplify constant template parameter type deduction for partial ordering (#160433)
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.
Added:
Modified:
clang/lib/Sema/SemaTemplateDeduction.cpp
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 62e867c44ad14..962fa4da75946 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -483,7 +483,7 @@ DeduceNonTypeTemplateArgument(Sema &S, TemplateParameterList *TemplateParams,
return TemplateDeductionResult::Inconsistent;
}
Deduced[NTTP.getIndex()] = Result;
- if (!S.getLangOpts().CPlusPlus17)
+ if (!S.getLangOpts().CPlusPlus17 && !PartialOrdering)
return TemplateDeductionResult::Success;
if (NTTP.isExpandedParameterPack())
@@ -2652,28 +2652,11 @@ DeduceTemplateArguments(Sema &S, TemplateParameterList *TemplateParams,
getDeducedNTTParameterFromExpr(Info, P.getAsExpr())) {
switch (A.getKind()) {
case TemplateArgument::Expression: {
- const Expr *E = A.getAsExpr();
- // When checking NTTP, if either the parameter or the argument is
- // dependent, as there would be otherwise nothing to deduce, we force
- // the argument to the parameter type using this dependent implicit
- // cast, in order to maintain invariants. Now we can deduce the
- // resulting type from the original type, and deduce the original type
- // against the parameter we are checking.
- if (const auto *ICE = dyn_cast<ImplicitCastExpr>(E);
- ICE && ICE->getCastKind() == clang::CK_Dependent) {
- E = ICE->getSubExpr();
- if (auto Result = DeduceTemplateArgumentsByTypeMatch(
- S, TemplateParams, ICE->getType(), E->getType(), Info,
- Deduced, TDF_SkipNonDependent,
- PartialOrdering ? PartialOrderingKind::NonCall
- : PartialOrderingKind::None,
- /*DeducedFromArrayBound=*/false, HasDeducedAnyParam);
- Result != TemplateDeductionResult::Success)
- return Result;
- }
+ // The type of the value is the type of the expression as written.
return DeduceNonTypeTemplateArgument(
- S, TemplateParams, NTTP, DeducedTemplateArgument(A), E->getType(),
- Info, PartialOrdering, Deduced, HasDeducedAnyParam);
+ S, TemplateParams, NTTP, DeducedTemplateArgument(A),
+ A.getAsExpr()->IgnoreImplicitAsWritten()->getType(), Info,
+ PartialOrdering, Deduced, HasDeducedAnyParam);
}
case TemplateArgument::Integral:
case TemplateArgument::StructuralValue:
More information about the cfe-commits
mailing list