[clang] [clang] simplify constant template parameter type deduction for partial ordering (PR #160433)

Matheus Izvekov via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 24 09:19:28 PDT 2025


================
@@ -2653,23 +2653,11 @@ DeduceTemplateArguments(Sema &S, TemplateParameterList *TemplateParams,
       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) {
+        // The type of the value is the type of the expression before any
+        // implicit conversions.
+        if (const auto *ICE = dyn_cast<ImplicitCastExpr>(E)) {
           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;
+          assert(!isa<ImplicitCastExpr>(E));
----------------
mizvekov wrote:

In general yes, but I think in this case it would be likely to be a bug, that's why I didn't use that and left the assert.

This could happen in a case where a constant template parameter was substituted for, but a Subst node was not left behind.

And here it's only implicit casts, we want the type of the template argument as written.

https://github.com/llvm/llvm-project/pull/160433


More information about the cfe-commits mailing list