[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / clang / test / SemaCXX / deleted-function.cpp
blobbd6fc09eeb7798dd244dbc7db9055e1300aa1164
1 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -fcxx-exceptions %s
3 int i = delete; // expected-error {{only functions can have deleted definitions}}
5 void fn() = delete; // expected-note {{candidate function has been explicitly deleted}}
7 void fn2(); // expected-note {{previous declaration is here}}
8 void fn2() = delete; // expected-error {{deleted definition must be first declaration}}
10 void fn3() = delete; // expected-note {{previous definition is here}}
11 void fn3() { // expected-error {{redefinition}}
14 void ov(int) {} // expected-note {{candidate function}}
15 void ov(double) = delete; // expected-note {{candidate function has been explicitly deleted}}
17 struct WithDel {
18 WithDel() = delete; // expected-note {{'WithDel' has been explicitly marked deleted here}}
19 void fn() = delete; // expected-note {{'fn' has been explicitly marked deleted here}}
20 operator int() = delete; // expected-note {{'operator int' has been explicitly marked deleted here}}
21 void operator +(int) = delete;
23 int i = delete; // expected-error {{only functions can have deleted definitions}}
26 void test() {
27 fn(); // expected-error {{call to deleted function 'fn'}}
28 ov(1);
29 ov(1.0); // expected-error {{call to deleted function 'ov'}}
31 WithDel dd; // expected-error {{call to deleted constructor of 'WithDel'}}
32 WithDel *d = 0;
33 d->fn(); // expected-error {{attempt to use a deleted function}}
34 int i = *d; // expected-error {{invokes a deleted function}}
37 struct DelDtor {
38 ~DelDtor() = delete; // expected-note 9{{here}}
40 void f() {
41 DelDtor *p = new DelDtor[3]; // expected-error {{attempt to use a deleted function}}
42 delete [] p; // expected-error {{attempt to use a deleted function}}
43 const DelDtor &dd2 = DelDtor(); // expected-error {{attempt to use a deleted function}}
44 DelDtor dd; // expected-error {{attempt to use a deleted function}}
45 throw dd; // expected-error {{attempt to use a deleted function}}
47 struct X : DelDtor {
48 ~X() {} // expected-error {{attempt to use a deleted function}}
50 struct Y {
51 DelDtor dd;
52 ~Y() {} // expected-error {{attempt to use a deleted function}}
54 struct Z : virtual DelDtor {
55 ~Z() {} // expected-error {{attempt to use a deleted function}}
57 DelDtor dd; // expected-error {{attempt to use a deleted function}}
59 template<typename> void test2() = delete;
60 template void test2<int>();
62 template<typename> void test3() = delete;
63 template<typename> void test3();
64 template void test3<int>();
66 void test4() {} // expected-note {{previous definition is here}}
67 void test4() = delete; // expected-error {{redefinition of 'test4'}}
69 struct DelCtor { // expected-note 4{{implicit}}
70 DelCtor(int) = delete; // expected-note 14{{deleted}}
71 // ensure the class is not an aggregate
72 DelCtor(int, int, int, int);
74 DelCtor dc1 = 0; // expected-error {{deleted}}
75 DelCtor dc2(0); // expected-error {{deleted}}
76 DelCtor dc3 = {0}; // expected-error {{deleted}}
77 DelCtor dc4{0}; // expected-error {{deleted}}
78 DelCtor dc5 = (DelCtor)0; // expected-error {{deleted}}
79 DelCtor dc6 = DelCtor(0); // expected-error {{deleted}}
80 DelCtor dc7 = DelCtor{0}; // expected-error {{deleted}}
81 DelCtor *dc8 = new DelCtor(0); // expected-error {{deleted}}
82 DelCtor *dc9 = new DelCtor{0}; // expected-error {{deleted}}
83 DelCtor dc10[] = {0}; // expected-error {{deleted}}
84 int use_dc(DelCtor); // expected-note 2{{here}}
85 int dc11 = use_dc(0); // expected-error {{deleted}}
86 int dc12 = use_dc({0}); // expected-error {{deleted}}
87 int use_dcr(const DelCtor &); // expected-note {{here}}
88 int dc13 = use_dcr(0); // expected-error {{deleted}}
89 int dc14 = use_dcr({0}); // expected-error {{deleted}}
91 struct DelCtorTemplate {
92 template<typename T> DelCtorTemplate(T) = delete; // expected-note {{deleted}}
94 int use_dct(const DelCtorTemplate &);
95 int dc15 = use_dct(0); // expected-error {{deleted}}