File: p4.cpp

package info (click to toggle)
swiftlang 6.1.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,791,604 kB
  • sloc: cpp: 9,901,740; ansic: 2,201,431; asm: 1,091,827; python: 308,252; objc: 82,166; f90: 80,126; lisp: 38,358; pascal: 25,559; sh: 20,429; ml: 5,058; perl: 4,745; makefile: 4,484; awk: 3,535; javascript: 3,018; xml: 918; fortran: 664; cs: 573; ruby: 396
file content (77 lines) | stat: -rw-r--r-- 2,679 bytes parent folder | download | duplicates (16)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// RUN: %clang_cc1 -std=c++20 -verify %s

template <int N>
struct A {
  ~A() = delete;                  // expected-note {{explicitly marked deleted}}
  ~A() requires(N == 1) = delete; // expected-note {{explicitly marked deleted}}
};

// FIXME: We should probably make it illegal to mix virtual and non-virtual methods
// this way. See CWG2488 and some discussion in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105699.
template <int N>
struct B {
  ~B() requires(N == 1) = delete; // expected-note {{explicitly marked deleted}}
  virtual ~B() = delete;          // expected-note {{explicitly marked deleted}}
};

template <int N>
concept CO1 = N == 1;

template <int N>
concept CO2 = N >
0;

template <int N>
struct C {
  ~C() = delete; // expected-note {{explicitly marked deleted}}
  ~C() requires(CO1<N>) = delete;
  ~C() requires(CO1<N> &&CO2<N>) = delete; // expected-note {{explicitly marked deleted}}
};

template <int N>
struct D {
  ~D() requires(N != 0) = delete; // expected-note {{explicitly marked deleted}}
  // expected-note@-1 {{candidate function has been explicitly deleted}}
  // expected-note@-2 {{candidate function not viable: constraints not satisfied}}
  // expected-note@-3 {{evaluated to false}}
  ~D() requires(N == 1) = delete;
  // expected-note@-1 {{candidate function has been explicitly deleted}}
  // expected-note@-2 {{candidate function not viable: constraints not satisfied}}
  // expected-note@-3 {{evaluated to false}}
};

template <class T>
concept Foo = requires(T t) {
  {t.foo()};
};

template <int N>
struct E {
  void foo();
  ~E();
  ~E() requires Foo<E> = delete; // expected-note {{explicitly marked deleted}}
};

template struct A<1>;
template struct A<2>;
template struct B<1>;
template struct B<2>;
template struct C<1>;
template struct C<2>;
template struct D<0>; // expected-error {{no viable destructor found for class 'D<0>'}} expected-note {{in instantiation of template}}
template struct D<1>; // expected-error {{destructor of class 'D<1>' is ambiguous}} expected-note {{in instantiation of template}}
template struct D<2>;
template struct E<1>;

int main() {
  A<1> a1; // expected-error {{attempt to use a deleted function}}
  A<2> a2; // expected-error {{attempt to use a deleted function}}
  B<1> b1; // expected-error {{attempt to use a deleted function}}
  B<2> b2; // expected-error {{attempt to use a deleted function}}
  C<1> c1; // expected-error {{attempt to use a deleted function}}
  C<2> c2; // expected-error {{attempt to use a deleted function}}
  D<0> d0;
  D<1> d1;
  D<2> d2; // expected-error {{attempt to use a deleted function}}
  E<1> e1; // expected-error {{attempt to use a deleted function}}
}