[Clang] Implement fix for DR2628
authorRoy Jacobson <roi.jacobson1@gmail.com>
Sun, 18 Sep 2022 20:07:25 +0000 (23:07 +0300)
committerRoy Jacobson <roi.jacobson1@gmail.com>
Mon, 19 Sep 2022 21:07:41 +0000 (00:07 +0300)
Implement suggested fix for [[ https://cplusplus.github.io/CWG/issues/2628.html | DR2628. ]] Couldn't update the DR docs because there hasn't been a DR index since it was filed, but the tests still run in CI.

Note: I only transfer the constructor constraints, not the struct constraints. I think that's OK because the struct constraints are the same
for all constructors so they don't affect the overload resolution, and if they deduce to something that doesn't pass the constraints
we catch it anyway. So (hopefully) that should be more efficient without sacrificing correctness.

Closes:
https://github.com/llvm/llvm-project/issues/57646
https://github.com/llvm/llvm-project/issues/43829

Reviewed By: erichkeane

Differential Revision: https://reviews.llvm.org/D134145

clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaTemplate.cpp
clang/test/CXX/drs/dr26xx.cpp [new file with mode: 0644]

index 2546142..96b0c7e 100644 (file)
@@ -151,6 +151,10 @@ Bug Fixes
   `Issue 57369 <https://github.com/llvm/llvm-project/issues/57369>`_
   `Issue 57643 <https://github.com/llvm/llvm-project/issues/57643>`_
   `Issue 57793 <https://github.com/llvm/llvm-project/issues/57793>`_
+- Respect constructor constraints during class template argument deduction (CTAD).
+  This is the suggested resolution to CWG DR2628.
+  `Issue 57646 <https://github.com/llvm/llvm-project/issues/57646>`_
+  `Issue 43829 <https://github.com/llvm/llvm-project/issues/43829>`_
 
 
 Improvements to Clang's diagnostics
index e0f913e..2ab59e7 100644 (file)
@@ -2445,6 +2445,8 @@ private:
                                       TInfo->getType(), TInfo, LocEnd, Ctor);
     Guide->setImplicit();
     Guide->setParams(Params);
+    if (Ctor && Ctor->getTrailingRequiresClause())
+      Guide->setTrailingRequiresClause(Ctor->getTrailingRequiresClause());
 
     for (auto *Param : Params)
       Param->setDeclContext(Guide);
diff --git a/clang/test/CXX/drs/dr26xx.cpp b/clang/test/CXX/drs/dr26xx.cpp
new file mode 100644 (file)
index 0000000..1178cef
--- /dev/null
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify
+
+namespace dr2628 { // dr2628: yes
+
+template <bool A = false, bool B = false>
+struct foo {
+  constexpr foo() requires (!A && !B) = delete; // #DR2628_CTOR
+  constexpr foo() requires (A || B) = delete;
+};
+
+void f() {
+  foo fooable; // expected-error {{call to deleted}}
+  // expected-note@#DR2628_CTOR {{marked deleted here}}
+}
+
+}