royjacobson created this revision. Herald added a project: All. royjacobson requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
Implement suggested fix for DR2628. Coulnd't update the DR docs because there hasn't been a new DRs index, but the tests still run. 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 that should be more efficient without (hopefully) sacrificing correctness. Closes: https://github.com/llvm/llvm-project/issues/57646 https://github.com/llvm/llvm-project/issues/43829 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D134145 Files: clang/lib/Sema/SemaTemplate.cpp clang/test/CXX/drs/dr26xx.cpp Index: clang/test/CXX/drs/dr26xx.cpp =================================================================== --- /dev/null +++ clang/test/CXX/drs/dr26xx.cpp @@ -0,0 +1,15 @@ +// 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; // expected-note {{marked deleted here}} + constexpr foo() requires (A || B) = delete; +}; + +void f() { + foo fooable; // expected-error {{call to deleted}} +} + +} Index: clang/lib/Sema/SemaTemplate.cpp =================================================================== --- clang/lib/Sema/SemaTemplate.cpp +++ clang/lib/Sema/SemaTemplate.cpp @@ -2445,6 +2445,8 @@ 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);
Index: clang/test/CXX/drs/dr26xx.cpp =================================================================== --- /dev/null +++ clang/test/CXX/drs/dr26xx.cpp @@ -0,0 +1,15 @@ +// 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; // expected-note {{marked deleted here}} + constexpr foo() requires (A || B) = delete; +}; + +void f() { + foo fooable; // expected-error {{call to deleted}} +} + +} Index: clang/lib/Sema/SemaTemplate.cpp =================================================================== --- clang/lib/Sema/SemaTemplate.cpp +++ clang/lib/Sema/SemaTemplate.cpp @@ -2445,6 +2445,8 @@ 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);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits