2012-02-18 12:13:32 +08:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -fcxx-exceptions %s
|
2009-03-25 06:27:57 +08:00
|
|
|
|
|
|
|
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}}
|
|
|
|
|
2011-05-07 04:44:56 +08:00
|
|
|
void fn3() = delete; // expected-note {{previous definition is here}}
|
|
|
|
void fn3() { // expected-error {{redefinition}}
|
2009-03-25 06:27:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ov(int) {} // expected-note {{candidate function}}
|
|
|
|
void ov(double) = delete; // expected-note {{candidate function has been explicitly deleted}}
|
|
|
|
|
2009-04-13 01:16:29 +08:00
|
|
|
struct WithDel {
|
2013-12-19 07:30:06 +08:00
|
|
|
WithDel() = delete; // expected-note {{'WithDel' has been explicitly marked deleted here}}
|
|
|
|
void fn() = delete; // expected-note {{'fn' has been explicitly marked deleted here}}
|
|
|
|
operator int() = delete; // expected-note {{'operator int' has been explicitly marked deleted here}}
|
2009-04-13 01:16:29 +08:00
|
|
|
void operator +(int) = delete;
|
2009-04-13 01:41:24 +08:00
|
|
|
|
|
|
|
int i = delete; // expected-error {{only functions can have deleted definitions}}
|
2009-04-13 01:16:29 +08:00
|
|
|
};
|
|
|
|
|
2009-03-25 06:27:57 +08:00
|
|
|
void test() {
|
|
|
|
fn(); // expected-error {{call to deleted function 'fn'}}
|
|
|
|
ov(1);
|
|
|
|
ov(1.0); // expected-error {{call to deleted function 'ov'}}
|
2009-04-13 01:16:29 +08:00
|
|
|
|
2010-03-10 19:27:22 +08:00
|
|
|
WithDel dd; // expected-error {{call to deleted constructor of 'WithDel'}}
|
2009-04-13 01:16:29 +08:00
|
|
|
WithDel *d = 0;
|
|
|
|
d->fn(); // expected-error {{attempt to use a deleted function}}
|
2009-12-19 16:11:05 +08:00
|
|
|
int i = *d; // expected-error {{invokes a deleted function}}
|
2009-03-25 06:27:57 +08:00
|
|
|
}
|
2012-02-18 12:13:32 +08:00
|
|
|
|
|
|
|
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}}
|
2012-06-26 05:55:30 +08:00
|
|
|
|
|
|
|
template<typename> void test2() = delete;
|
|
|
|
template void test2<int>();
|
|
|
|
|
2012-07-17 02:50:45 +08:00
|
|
|
template<typename> void test3() = delete;
|
2012-06-26 05:55:30 +08:00
|
|
|
template<typename> void test3();
|
2012-07-17 02:50:45 +08:00
|
|
|
template void test3<int>();
|
2012-06-30 02:00:25 +08:00
|
|
|
|
|
|
|
void test4() {} // expected-note {{previous definition is here}}
|
|
|
|
void test4() = delete; // expected-error {{redefinition of 'test4'}}
|
2015-02-25 04:41:36 +08:00
|
|
|
|
|
|
|
struct DelCtor { // expected-note 4{{implicit}}
|
2015-02-25 05:16:19 +08:00
|
|
|
DelCtor(int) = delete; // expected-note 14{{deleted}}
|
2015-02-25 04:41:36 +08:00
|
|
|
// ensure the class is not an aggregate
|
|
|
|
DelCtor(int, int, int, int);
|
|
|
|
};
|
|
|
|
DelCtor dc1 = 0; // expected-error {{deleted}}
|
|
|
|
DelCtor dc2(0); // expected-error {{deleted}}
|
|
|
|
DelCtor dc3 = {0}; // expected-error {{deleted}}
|
|
|
|
DelCtor dc4{0}; // expected-error {{deleted}}
|
|
|
|
DelCtor dc5 = (DelCtor)0; // expected-error {{deleted}}
|
|
|
|
DelCtor dc6 = DelCtor(0); // expected-error {{deleted}}
|
|
|
|
DelCtor dc7 = DelCtor{0}; // expected-error {{deleted}}
|
|
|
|
DelCtor *dc8 = new DelCtor(0); // expected-error {{deleted}}
|
|
|
|
DelCtor *dc9 = new DelCtor{0}; // expected-error {{deleted}}
|
|
|
|
DelCtor dc10[] = {0}; // expected-error {{deleted}}
|
|
|
|
int use_dc(DelCtor); // expected-note 2{{here}}
|
|
|
|
int dc11 = use_dc(0); // expected-error {{deleted}}
|
|
|
|
int dc12 = use_dc({0}); // expected-error {{deleted}}
|
|
|
|
int use_dcr(const DelCtor &); // expected-note {{here}}
|
2015-02-25 05:16:19 +08:00
|
|
|
int dc13 = use_dcr(0); // expected-error {{deleted}}
|
2015-02-25 04:41:36 +08:00
|
|
|
int dc14 = use_dcr({0}); // expected-error {{deleted}}
|
2015-02-25 05:44:43 +08:00
|
|
|
|
|
|
|
struct DelCtorTemplate {
|
|
|
|
template<typename T> DelCtorTemplate(T) = delete; // expected-note {{deleted}}
|
|
|
|
};
|
|
|
|
int use_dct(const DelCtorTemplate &);
|
|
|
|
int dc15 = use_dct(0); // expected-error {{deleted}}
|