Skip to content

Commit

Permalink
[Clang] Implement fix for DR2628
Browse files Browse the repository at this point in the history
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:
#57646
#43829

Reviewed By: erichkeane

Differential Revision: https://reviews.llvm.org/D134145
  • Loading branch information
royjacobson committed Sep 19, 2022
1 parent ce39bdb commit 368b683
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/Sema/SemaTemplate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2445,6 +2445,8 @@ struct ConvertConstructorToDeductionGuideTransform {
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);
Expand Down
16 changes: 16 additions & 0 deletions clang/test/CXX/drs/dr26xx.cpp
Original file line number Diff line number Diff line change
@@ -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}}
}

}

0 comments on commit 368b683

Please sign in to comment.