Richard Smith | 213d70b | 2012-02-18 04:13:32 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -fcxx-exceptions %s |
Sebastian Redl | 50de12f | 2009-03-24 22:27:57 +0000 | [diff] [blame] | 2 | |
| 3 | int i = delete; // expected-error {{only functions can have deleted definitions}} |
| 4 | |
| 5 | void fn() = delete; // expected-note {{candidate function has been explicitly deleted}} |
| 6 | |
| 7 | void fn2(); // expected-note {{previous declaration is here}} |
| 8 | void fn2() = delete; // expected-error {{deleted definition must be first declaration}} |
| 9 | |
Sean Hunt | 10620eb | 2011-05-06 20:44:56 +0000 | [diff] [blame] | 10 | void fn3() = delete; // expected-note {{previous definition is here}} |
| 11 | void fn3() { // expected-error {{redefinition}} |
Sebastian Redl | 50de12f | 2009-03-24 22:27:57 +0000 | [diff] [blame] | 12 | } |
| 13 | |
| 14 | void ov(int) {} // expected-note {{candidate function}} |
| 15 | void ov(double) = delete; // expected-note {{candidate function has been explicitly deleted}} |
| 16 | |
Sebastian Redl | e2b6833 | 2009-04-12 17:16:29 +0000 | [diff] [blame] | 17 | struct WithDel { |
Douglas Gregor | 745880f | 2009-12-20 22:01:25 +0000 | [diff] [blame] | 18 | WithDel() = delete; // expected-note {{function has been explicitly marked deleted here}} |
Sebastian Redl | e2b6833 | 2009-04-12 17:16:29 +0000 | [diff] [blame] | 19 | void fn() = delete; // expected-note {{function has been explicitly marked deleted here}} |
Eli Friedman | cfdc81a | 2009-12-19 08:11:05 +0000 | [diff] [blame] | 20 | operator int() = delete; // expected-note {{function has been explicitly marked deleted here}} |
Sebastian Redl | e2b6833 | 2009-04-12 17:16:29 +0000 | [diff] [blame] | 21 | void operator +(int) = delete; |
Sebastian Redl | 0b5e7fb | 2009-04-12 17:41:24 +0000 | [diff] [blame] | 22 | |
| 23 | int i = delete; // expected-error {{only functions can have deleted definitions}} |
Sebastian Redl | e2b6833 | 2009-04-12 17:16:29 +0000 | [diff] [blame] | 24 | }; |
| 25 | |
Sebastian Redl | 50de12f | 2009-03-24 22:27:57 +0000 | [diff] [blame] | 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'}} |
Sebastian Redl | e2b6833 | 2009-04-12 17:16:29 +0000 | [diff] [blame] | 30 | |
John McCall | 7c2342d | 2010-03-10 11:27:22 +0000 | [diff] [blame] | 31 | WithDel dd; // expected-error {{call to deleted constructor of 'WithDel'}} |
Sebastian Redl | e2b6833 | 2009-04-12 17:16:29 +0000 | [diff] [blame] | 32 | WithDel *d = 0; |
| 33 | d->fn(); // expected-error {{attempt to use a deleted function}} |
Eli Friedman | cfdc81a | 2009-12-19 08:11:05 +0000 | [diff] [blame] | 34 | int i = *d; // expected-error {{invokes a deleted function}} |
Sebastian Redl | 50de12f | 2009-03-24 22:27:57 +0000 | [diff] [blame] | 35 | } |
Richard Smith | 213d70b | 2012-02-18 04:13:32 +0000 | [diff] [blame] | 36 | |
| 37 | struct DelDtor { |
| 38 | ~DelDtor() = delete; // expected-note 9{{here}} |
| 39 | }; |
| 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}} |
| 46 | } |
| 47 | struct X : DelDtor { |
| 48 | ~X() {} // expected-error {{attempt to use a deleted function}} |
| 49 | }; |
| 50 | struct Y { |
| 51 | DelDtor dd; |
| 52 | ~Y() {} // expected-error {{attempt to use a deleted function}} |
| 53 | }; |
| 54 | struct Z : virtual DelDtor { |
| 55 | ~Z() {} // expected-error {{attempt to use a deleted function}} |
| 56 | }; |
| 57 | DelDtor dd; // expected-error {{attempt to use a deleted function}} |
David Blaikie | d9cf826 | 2012-06-25 21:55:30 +0000 | [diff] [blame] | 58 | |
| 59 | template<typename> void test2() = delete; |
| 60 | template void test2<int>(); |
| 61 | |
David Blaikie | 85f485a | 2012-07-16 18:50:45 +0000 | [diff] [blame] | 62 | template<typename> void test3() = delete; |
David Blaikie | d9cf826 | 2012-06-25 21:55:30 +0000 | [diff] [blame] | 63 | template<typename> void test3(); |
David Blaikie | 85f485a | 2012-07-16 18:50:45 +0000 | [diff] [blame] | 64 | template void test3<int>(); |
David Blaikie | 619ee6a | 2012-06-29 18:00:25 +0000 | [diff] [blame] | 65 | |
| 66 | void test4() {} // expected-note {{previous definition is here}} |
| 67 | void test4() = delete; // expected-error {{redefinition of 'test4'}} |