78 lines · cpp
1// RUN: %clang_cc1 -std=c++20 -verify %s2 3template <int N>4struct A {5 ~A() = delete; // expected-note {{explicitly marked deleted}}6 ~A() requires(N == 1) = delete; // expected-note {{explicitly marked deleted}}7};8 9// FIXME: We should probably make it illegal to mix virtual and non-virtual methods10// this way. See CWG2488 and some discussion in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105699.11template <int N>12struct B {13 ~B() requires(N == 1) = delete; // expected-note {{explicitly marked deleted}}14 virtual ~B() = delete; // expected-note {{explicitly marked deleted}}15};16 17template <int N>18concept CO1 = N == 1;19 20template <int N>21concept CO2 = N >220;23 24template <int N>25struct C {26 ~C() = delete; // expected-note {{explicitly marked deleted}}27 ~C() requires(CO1<N>) = delete;28 ~C() requires(CO1<N> &&CO2<N>) = delete; // expected-note {{explicitly marked deleted}}29};30 31template <int N>32struct D {33 ~D() requires(N != 0) = delete; // expected-note {{explicitly marked deleted}}34 // expected-note@-1 {{candidate function has been explicitly deleted}}35 // expected-note@-2 {{candidate function not viable: constraints not satisfied}}36 // expected-note@-3 {{evaluated to false}}37 ~D() requires(N == 1) = delete;38 // expected-note@-1 {{candidate function has been explicitly deleted}}39 // expected-note@-2 {{candidate function not viable: constraints not satisfied}}40 // expected-note@-3 {{evaluated to false}}41};42 43template <class T>44concept Foo = requires(T t) {45 {t.foo()};46};47 48template <int N>49struct E {50 void foo();51 ~E();52 ~E() requires Foo<E> = delete; // expected-note {{explicitly marked deleted}}53};54 55template struct A<1>;56template struct A<2>;57template struct B<1>;58template struct B<2>;59template struct C<1>;60template struct C<2>;61template struct D<0>; // expected-error {{no viable destructor found for class 'D<0>'}} expected-note {{in instantiation of template}}62template struct D<1>; // expected-error {{destructor of class 'D<1>' is ambiguous}} expected-note {{in instantiation of template}}63template struct D<2>;64template struct E<1>;65 66int main() {67 A<1> a1; // expected-error {{attempt to use a deleted function}}68 A<2> a2; // expected-error {{attempt to use a deleted function}}69 B<1> b1; // expected-error {{attempt to use a deleted function}}70 B<2> b2; // expected-error {{attempt to use a deleted function}}71 C<1> c1; // expected-error {{attempt to use a deleted function}}72 C<2> c2; // expected-error {{attempt to use a deleted function}}73 D<0> d0;74 D<1> d1;75 D<2> d2; // expected-error {{attempt to use a deleted function}}76 E<1> e1; // expected-error {{attempt to use a deleted function}}77}78