[Clang] constraints partial ordering should work with deduction guide
authorYuanfang Chen <yuanfang.chen@sony.com>
Wed, 19 Oct 2022 00:19:58 +0000 (17:19 -0700)
committerYuanfang Chen <yuanfang.chen@sony.com>
Wed, 19 Oct 2022 00:30:47 +0000 (17:30 -0700)
D128750 incorrectly skips constraints partial ordering for deduction guide.
This patch reverts that part.

Fixes https://github.com/llvm/llvm-project/issues/58456.

clang/lib/Sema/SemaTemplateDeduction.cpp
clang/test/SemaTemplate/deduction-guide-partial-ordering.cpp [new file with mode: 0644]

index 00b1cf1..0572a66 100644 (file)
@@ -5243,8 +5243,7 @@ FunctionTemplateDecl *Sema::getMoreSpecializedTemplate(
     }
   }
 
-  if (!Context.getLangOpts().CPlusPlus20 || isa<CXXDeductionGuideDecl>(FD1) ||
-      isa<CXXDeductionGuideDecl>(FD2))
+  if (!Context.getLangOpts().CPlusPlus20)
     return nullptr;
 
   // Match GCC on not implementing [temp.func.order]p6.2.1.
diff --git a/clang/test/SemaTemplate/deduction-guide-partial-ordering.cpp b/clang/test/SemaTemplate/deduction-guide-partial-ordering.cpp
new file mode 100644 (file)
index 0000000..4f57d07
--- /dev/null
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -std=c++20 -verify %s
+// expected-no-diagnostics
+
+namespace pr58456 {
+  template<typename>
+  struct s {
+    constexpr s(auto) {
+    }
+  };
+
+  template<typename T>
+  s(T) -> s<int>;
+
+  template<typename T> requires true
+  s(T) -> s<int>;
+
+  void f() {
+    auto const y = s(0);
+  }
+}