summaryrefslogtreecommitdiff
path: root/clang/test/SemaCXX/deleted-function.cpp
blob: d13fd0eb7b4f61486caea76033651fd7fce1d3b7 (about) (plain)
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
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -fcxx-exceptions %s

int i = delete; // expected-error {{only functions can have deleted definitions}}

void fn() = delete; // expected-note {{candidate function has been explicitly deleted}}

void fn2(); // expected-note {{previous declaration is here}}
void fn2() = delete; // expected-error {{deleted definition must be first declaration}}

void fn3() = delete; // expected-note {{previous definition is here}}
void fn3() { // expected-error {{redefinition}}
}

void ov(int) {} // expected-note {{candidate function}}
void ov(double) = delete; // expected-note {{candidate function has been explicitly deleted}}

struct WithDel {
  WithDel() = delete; // expected-note {{function has been explicitly marked deleted here}}
  void fn() = delete; // expected-note {{function has been explicitly marked deleted here}}
  operator int() = delete; // expected-note {{function has been explicitly marked deleted here}}
  void operator +(int) = delete;

  int i = delete; // expected-error {{only functions can have deleted definitions}}
};

void test() {
  fn(); // expected-error {{call to deleted function 'fn'}}
  ov(1);
  ov(1.0); // expected-error {{call to deleted function 'ov'}}

  WithDel dd; // expected-error {{call to deleted constructor of 'WithDel'}}
  WithDel *d = 0;
  d->fn(); // expected-error {{attempt to use a deleted function}}
  int i = *d; // expected-error {{invokes a deleted function}}
}

struct DelDtor {
  ~DelDtor() = delete; // expected-note 9{{here}}
};
void f() {
  DelDtor *p = new DelDtor[3]; // expected-error {{attempt to use a deleted function}}
  delete [] p; // expected-error {{attempt to use a deleted function}}
  const DelDtor &dd2 = DelDtor(); // expected-error {{attempt to use a deleted function}}
  DelDtor dd; // expected-error {{attempt to use a deleted function}}
  throw dd; // expected-error {{attempt to use a deleted function}}
}
struct X : DelDtor {
  ~X() {} // expected-error {{attempt to use a deleted function}}
};
struct Y {
  DelDtor dd;
  ~Y() {} // expected-error {{attempt to use a deleted function}}
};
struct Z : virtual DelDtor {
  ~Z() {} // expected-error {{attempt to use a deleted function}}
};
DelDtor dd; // expected-error {{attempt to use a deleted function}}