Richard Smith | 762bb9d | 2011-10-13 22:29:44 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s |
Sean Hunt | 1f2f384 | 2011-05-17 00:19:05 +0000 | [diff] [blame] | 2 | |
| 3 | struct non_trivial { |
| 4 | non_trivial(); |
| 5 | non_trivial(const non_trivial&); |
| 6 | non_trivial& operator = (const non_trivial&); |
| 7 | ~non_trivial(); |
| 8 | }; |
| 9 | |
Richard Smith | 6c4c36c | 2012-03-30 20:53:28 +0000 | [diff] [blame] | 10 | union bad_union { |
| 11 | non_trivial nt; // expected-note {{non-trivial default constructor}} |
Sean Hunt | 1f2f384 | 2011-05-17 00:19:05 +0000 | [diff] [blame] | 12 | }; |
Douglas Gregor | e4e68d4 | 2012-02-15 19:33:52 +0000 | [diff] [blame] | 13 | bad_union u; // expected-error {{call to implicitly-deleted default constructor}} |
Richard Smith | 6c4c36c | 2012-03-30 20:53:28 +0000 | [diff] [blame] | 14 | union bad_union2 { // expected-note {{all data members are const-qualified}} |
Sean Hunt | 1f2f384 | 2011-05-17 00:19:05 +0000 | [diff] [blame] | 15 | const int i; |
| 16 | }; |
Douglas Gregor | e4e68d4 | 2012-02-15 19:33:52 +0000 | [diff] [blame] | 17 | bad_union2 u2; // expected-error {{call to implicitly-deleted default constructor}} |
Sean Hunt | 1f2f384 | 2011-05-17 00:19:05 +0000 | [diff] [blame] | 18 | |
Richard Smith | 6c4c36c | 2012-03-30 20:53:28 +0000 | [diff] [blame] | 19 | struct bad_anon { |
Sean Hunt | 1f2f384 | 2011-05-17 00:19:05 +0000 | [diff] [blame] | 20 | union { |
Richard Smith | 6c4c36c | 2012-03-30 20:53:28 +0000 | [diff] [blame] | 21 | non_trivial nt; // expected-note {{non-trivial default constructor}} |
Sean Hunt | 1f2f384 | 2011-05-17 00:19:05 +0000 | [diff] [blame] | 22 | }; |
| 23 | }; |
Douglas Gregor | e4e68d4 | 2012-02-15 19:33:52 +0000 | [diff] [blame] | 24 | bad_anon a; // expected-error {{call to implicitly-deleted default constructor}} |
Richard Smith | 6c4c36c | 2012-03-30 20:53:28 +0000 | [diff] [blame] | 25 | struct bad_anon2 { |
| 26 | union { // expected-note {{all data members of an anonymous union member are const-qualified}} |
Sean Hunt | 1f2f384 | 2011-05-17 00:19:05 +0000 | [diff] [blame] | 27 | const int i; |
| 28 | }; |
| 29 | }; |
Douglas Gregor | e4e68d4 | 2012-02-15 19:33:52 +0000 | [diff] [blame] | 30 | bad_anon2 a2; // expected-error {{call to implicitly-deleted default constructor}} |
Sean Hunt | 1f2f384 | 2011-05-17 00:19:05 +0000 | [diff] [blame] | 31 | |
| 32 | // This would be great except that we implement |
| 33 | union good_union { |
| 34 | const int i; |
| 35 | float f; |
| 36 | }; |
| 37 | good_union gu; |
| 38 | struct good_anon { |
| 39 | union { |
| 40 | const int i; |
| 41 | float f; |
| 42 | }; |
| 43 | }; |
| 44 | good_anon ga; |
| 45 | |
| 46 | struct good : non_trivial { |
| 47 | non_trivial nt; |
| 48 | }; |
| 49 | good g; |
Sean Hunt | f1922d2 | 2011-05-17 20:44:39 +0000 | [diff] [blame] | 50 | |
Richard Smith | 6c4c36c | 2012-03-30 20:53:28 +0000 | [diff] [blame] | 51 | struct bad_const { |
| 52 | const good g; // expected-note {{field 'g' of const-qualified type 'const good' would not be initialized}} |
Sean Hunt | f1922d2 | 2011-05-17 20:44:39 +0000 | [diff] [blame] | 53 | }; |
Douglas Gregor | e4e68d4 | 2012-02-15 19:33:52 +0000 | [diff] [blame] | 54 | bad_const bc; // expected-error {{call to implicitly-deleted default constructor}} |
Sean Hunt | f1922d2 | 2011-05-17 20:44:39 +0000 | [diff] [blame] | 55 | |
| 56 | struct good_const { |
| 57 | const non_trivial nt; |
| 58 | }; |
| 59 | good_const gc; |
| 60 | |
| 61 | struct no_default { |
Richard Smith | 5bdaac5 | 2012-04-02 20:59:25 +0000 | [diff] [blame] | 62 | no_default() = delete; // expected-note 3{{deleted here}} |
Sean Hunt | f1922d2 | 2011-05-17 20:44:39 +0000 | [diff] [blame] | 63 | }; |
| 64 | struct no_dtor { |
Richard Smith | 6c4c36c | 2012-03-30 20:53:28 +0000 | [diff] [blame] | 65 | ~no_dtor() = delete; // expected-note 2{{deleted here}} |
Sean Hunt | f1922d2 | 2011-05-17 20:44:39 +0000 | [diff] [blame] | 66 | }; |
| 67 | |
Richard Smith | 6c4c36c | 2012-03-30 20:53:28 +0000 | [diff] [blame] | 68 | struct bad_field_default { |
| 69 | no_default nd; // expected-note {{field 'nd' has a deleted default constructor}} |
Sean Hunt | f1922d2 | 2011-05-17 20:44:39 +0000 | [diff] [blame] | 70 | }; |
Douglas Gregor | e4e68d4 | 2012-02-15 19:33:52 +0000 | [diff] [blame] | 71 | bad_field_default bfd; // expected-error {{call to implicitly-deleted default constructor}} |
Richard Smith | 6c4c36c | 2012-03-30 20:53:28 +0000 | [diff] [blame] | 72 | struct bad_base_default : no_default { // expected-note {{base class 'no_default' has a deleted default constructor}} |
Sean Hunt | f1922d2 | 2011-05-17 20:44:39 +0000 | [diff] [blame] | 73 | }; |
Douglas Gregor | e4e68d4 | 2012-02-15 19:33:52 +0000 | [diff] [blame] | 74 | bad_base_default bbd; // expected-error {{call to implicitly-deleted default constructor}} |
Sean Hunt | f1922d2 | 2011-05-17 20:44:39 +0000 | [diff] [blame] | 75 | |
Richard Smith | 6c4c36c | 2012-03-30 20:53:28 +0000 | [diff] [blame] | 76 | struct bad_field_dtor { |
| 77 | no_dtor nd; // expected-note {{field 'nd' has a deleted destructor}} |
Sean Hunt | f1922d2 | 2011-05-17 20:44:39 +0000 | [diff] [blame] | 78 | }; |
Douglas Gregor | e4e68d4 | 2012-02-15 19:33:52 +0000 | [diff] [blame] | 79 | bad_field_dtor bfx; // expected-error {{call to implicitly-deleted default constructor}} |
Richard Smith | 6c4c36c | 2012-03-30 20:53:28 +0000 | [diff] [blame] | 80 | struct bad_base_dtor : no_dtor { // expected-note {{base class 'no_dtor' has a deleted destructor}} |
Sean Hunt | f1922d2 | 2011-05-17 20:44:39 +0000 | [diff] [blame] | 81 | }; |
Douglas Gregor | e4e68d4 | 2012-02-15 19:33:52 +0000 | [diff] [blame] | 82 | bad_base_dtor bbx; // expected-error {{call to implicitly-deleted default constructor}} |
Sean Hunt | f1922d2 | 2011-05-17 20:44:39 +0000 | [diff] [blame] | 83 | |
| 84 | struct ambiguous_default { |
| 85 | ambiguous_default(); |
| 86 | ambiguous_default(int = 2); |
| 87 | }; |
Richard Smith | 6c4c36c | 2012-03-30 20:53:28 +0000 | [diff] [blame] | 88 | struct has_amb_field { |
| 89 | ambiguous_default ad; // expected-note {{field 'ad' has multiple default constructors}} |
Sean Hunt | f1922d2 | 2011-05-17 20:44:39 +0000 | [diff] [blame] | 90 | }; |
Douglas Gregor | e4e68d4 | 2012-02-15 19:33:52 +0000 | [diff] [blame] | 91 | has_amb_field haf; // expected-error {{call to implicitly-deleted default constructor}} |
Sean Hunt | f1922d2 | 2011-05-17 20:44:39 +0000 | [diff] [blame] | 92 | |
Sean Hunt | f1922d2 | 2011-05-17 20:44:39 +0000 | [diff] [blame] | 93 | class inaccessible_default { |
| 94 | inaccessible_default(); |
| 95 | }; |
Richard Smith | 6c4c36c | 2012-03-30 20:53:28 +0000 | [diff] [blame] | 96 | struct has_inacc_field { |
| 97 | inaccessible_default id; // expected-note {{field 'id' has an inaccessible default constructor}} |
Sean Hunt | f1922d2 | 2011-05-17 20:44:39 +0000 | [diff] [blame] | 98 | }; |
Douglas Gregor | e4e68d4 | 2012-02-15 19:33:52 +0000 | [diff] [blame] | 99 | has_inacc_field hif; // expected-error {{call to implicitly-deleted default constructor}} |
Sean Hunt | f1922d2 | 2011-05-17 20:44:39 +0000 | [diff] [blame] | 100 | |
| 101 | class friend_default { |
| 102 | friend struct has_friend; |
| 103 | friend_default(); |
| 104 | }; |
| 105 | struct has_friend { |
| 106 | friend_default fd; |
| 107 | }; |
| 108 | has_friend hf; |
| 109 | |
Richard Smith | 6c4c36c | 2012-03-30 20:53:28 +0000 | [diff] [blame] | 110 | struct defaulted_delete { |
Richard Smith | 5bdaac5 | 2012-04-02 20:59:25 +0000 | [diff] [blame] | 111 | no_default nd; // expected-note {{because field 'nd' has a deleted default constructor}} |
| 112 | defaulted_delete() = default; // expected-note{{implicitly deleted here}} |
Sean Hunt | f1922d2 | 2011-05-17 20:44:39 +0000 | [diff] [blame] | 113 | }; |
Douglas Gregor | e4e68d4 | 2012-02-15 19:33:52 +0000 | [diff] [blame] | 114 | defaulted_delete dd; // expected-error {{call to implicitly-deleted default constructor}} |
Sean Hunt | f1922d2 | 2011-05-17 20:44:39 +0000 | [diff] [blame] | 115 | |
| 116 | struct late_delete { |
| 117 | no_default nd; |
| 118 | late_delete(); |
| 119 | }; |
| 120 | late_delete::late_delete() = default; // expected-error {{would delete it}} |
Richard Smith | 16ee819 | 2011-09-18 00:06:34 +0000 | [diff] [blame] | 121 | |
| 122 | // See also rdar://problem/8125400. |
| 123 | namespace empty { |
Douglas Gregor | 221c27f | 2012-02-24 21:25:53 +0000 | [diff] [blame] | 124 | static union {}; |
| 125 | static union { union {}; }; |
Richard Smith | 16ee819 | 2011-09-18 00:06:34 +0000 | [diff] [blame] | 126 | static union { struct {}; }; |
Douglas Gregor | 221c27f | 2012-02-24 21:25:53 +0000 | [diff] [blame] | 127 | static union { union { union {}; }; }; |
Richard Smith | 16ee819 | 2011-09-18 00:06:34 +0000 | [diff] [blame] | 128 | static union { union { struct {}; }; }; |
Douglas Gregor | 221c27f | 2012-02-24 21:25:53 +0000 | [diff] [blame] | 129 | static union { struct { union {}; }; }; |
Richard Smith | 16ee819 | 2011-09-18 00:06:34 +0000 | [diff] [blame] | 130 | static union { struct { struct {}; }; }; |
| 131 | } |