[clang] [clang] NFCI: don't check deduced constraints when partial ordering (PR #106882)

Matheus Izvekov via cfe-commits cfe-commits at lists.llvm.org
Sat Aug 31 19:26:49 PDT 2024


https://github.com/mizvekov created https://github.com/llvm/llvm-project/pull/106882

We were incorrectly applying [temp.deduct]p5 to partial ordering.

Marked as NFCI as I don't think the difference is actually observable in practice.
During partial ordering, the deduced arguments will mostly be dependent and thus cannot be checked.
Otherwise, later during overload resolution, if deduction succeeds in both directions,
we will perform subsumption check for the constraints ([temp.func.order]p6).

>From 5670a0baba65ba31da082d3fb373b9c2a85a73c3 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov <mizvekov at gmail.com>
Date: Sat, 31 Aug 2024 23:13:50 -0300
Subject: [PATCH] [clang] NFCI: don't check deduced constraints when partial
 ordering

We were incorrectly applying [temp.deduct]p5 to partial ordering.

Marked as NFCI as I don't think the difference is actually observable
in practice. During partial ordering, the deduced arguments will
mostly be dependent and thus cannot be checked. Otherwise, later
during overload resolution, if deduction succeeds in both directions,
we will perform subsumption check for the constraints ([temp.func.order]p6).
---
 clang/lib/Sema/SemaTemplateDeduction.cpp | 36 ++++++++++--------------
 1 file changed, 15 insertions(+), 21 deletions(-)

diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 11bc9f2d1e7484..01f18e5a325197 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -3313,10 +3313,12 @@ FinishTemplateArgumentDeduction(
   if (Trap.hasErrorOccurred())
     return TemplateDeductionResult::SubstitutionFailure;
 
-  if (auto Result = CheckDeducedArgumentConstraints(S, Partial, SugaredBuilder,
-                                                    CanonicalBuilder, Info);
-      Result != TemplateDeductionResult::Success)
-    return Result;
+  if (!IsPartialOrdering) {
+    if (auto Result = CheckDeducedArgumentConstraints(
+            S, Partial, SugaredBuilder, CanonicalBuilder, Info);
+        Result != TemplateDeductionResult::Success)
+      return Result;
+  }
 
   return TemplateDeductionResult::Success;
 }
@@ -3364,13 +3366,16 @@ static TemplateDeductionResult FinishTemplateArgumentDeduction(
   if (Trap.hasErrorOccurred())
     return TemplateDeductionResult::SubstitutionFailure;
 
-  if (auto Result = CheckDeducedArgumentConstraints(S, Template, SugaredBuilder,
-                                                    CanonicalBuilder, Info);
-      Result != TemplateDeductionResult::Success)
-    return Result;
+  if (!PartialOrdering) {
+    if (auto Result = CheckDeducedArgumentConstraints(
+            S, Template, SugaredBuilder, CanonicalBuilder, Info);
+        Result != TemplateDeductionResult::Success)
+      return Result;
+  }
 
   return TemplateDeductionResult::Success;
 }
+
 /// Complete template argument deduction for DeduceTemplateArgumentsFromType.
 /// FIXME: this is mostly duplicated with the above two versions. Deduplicate
 /// the three implementations.
@@ -5595,19 +5600,8 @@ static TemplateDeductionResult FinishTemplateArgumentDeduction(
       TDR != TemplateDeductionResult::Success)
     return TDR;
 
-  // C++20 [temp.deduct]p5 - Only check constraints when all parameters have
-  // been deduced.
-  if (!IsIncomplete) {
-    if (auto Result = CheckDeducedArgumentConstraints(S, FTD, SugaredBuilder,
-                                                      CanonicalBuilder, Info);
-        Result != TemplateDeductionResult::Success)
-      return Result;
-  }
-
-  if (Trap.hasErrorOccurred())
-    return TemplateDeductionResult::SubstitutionFailure;
-
-  return TemplateDeductionResult::Success;
+  return Trap.hasErrorOccurred() ? TemplateDeductionResult::SubstitutionFailure
+                                 : TemplateDeductionResult::Success;
 }
 
 /// Determine whether the function template \p FT1 is at least as



More information about the cfe-commits mailing list