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