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