Richard Smith | 1d0c9a8 | 2012-02-14 21:14:13 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -std=c++11 -verify %s |
| 2 | struct A { // expected-note 2{{candidate}} |
| 3 | A(int); // expected-note {{candidate}} |
| 4 | int n; |
| 5 | }; |
| 6 | int a = A().n; // expected-error {{no matching constructor}} |
| 7 | |
| 8 | struct B { |
Richard Smith | 5bdaac5 | 2012-04-02 20:59:25 +0000 | [diff] [blame] | 9 | B() = delete; // expected-note 3{{here}} |
Richard Smith | 1d0c9a8 | 2012-02-14 21:14:13 +0000 | [diff] [blame] | 10 | int n; |
| 11 | }; |
| 12 | int b = B().n; // expected-error {{call to deleted}} |
| 13 | |
Richard Smith | 6c4c36c | 2012-03-30 20:53:28 +0000 | [diff] [blame] | 14 | struct C { |
| 15 | B b; // expected-note {{deleted default constructor}} |
Richard Smith | 1d0c9a8 | 2012-02-14 21:14:13 +0000 | [diff] [blame] | 16 | }; |
Douglas Gregor | e4e68d4 | 2012-02-15 19:33:52 +0000 | [diff] [blame] | 17 | int c = C().b.n; // expected-error {{call to implicitly-deleted default}} |
Richard Smith | 1d0c9a8 | 2012-02-14 21:14:13 +0000 | [diff] [blame] | 18 | |
Richard Smith | 6c4c36c | 2012-03-30 20:53:28 +0000 | [diff] [blame] | 19 | struct D { |
| 20 | D() = default; // expected-note {{here}} |
Richard Smith | 5bdaac5 | 2012-04-02 20:59:25 +0000 | [diff] [blame] | 21 | B b; // expected-note {{'b' has a deleted default constructor}} |
Richard Smith | 1d0c9a8 | 2012-02-14 21:14:13 +0000 | [diff] [blame] | 22 | }; |
Douglas Gregor | e4e68d4 | 2012-02-15 19:33:52 +0000 | [diff] [blame] | 23 | int d = D().b.n; // expected-error {{call to implicitly-deleted default}} |
Richard Smith | 1d0c9a8 | 2012-02-14 21:14:13 +0000 | [diff] [blame] | 24 | |
| 25 | struct E { |
| 26 | E() = default; |
| 27 | int n; |
| 28 | }; |
| 29 | int e = E().n; // ok |
| 30 | |
| 31 | struct F { |
| 32 | F(); |
| 33 | int n; |
| 34 | }; |
| 35 | int f = F().n; // ok |
| 36 | |
Richard Smith | 6c4c36c | 2012-03-30 20:53:28 +0000 | [diff] [blame] | 37 | union G { |
| 38 | F f; // expected-note {{non-trivial default constructor}} |
Richard Smith | 1d0c9a8 | 2012-02-14 21:14:13 +0000 | [diff] [blame] | 39 | }; |
Douglas Gregor | e4e68d4 | 2012-02-15 19:33:52 +0000 | [diff] [blame] | 40 | int g = G().f.n; // expected-error {{call to implicitly-deleted default}} |
Richard Smith | 1d0c9a8 | 2012-02-14 21:14:13 +0000 | [diff] [blame] | 41 | |
| 42 | struct H { |
| 43 | int n; |
| 44 | private: |
| 45 | H(); // expected-note {{here}} |
| 46 | }; |
| 47 | int h = H().n; // expected-error {{private constructor}} |
| 48 | |
Richard Smith | 6c4c36c | 2012-03-30 20:53:28 +0000 | [diff] [blame] | 49 | struct I { |
| 50 | H h; // expected-note {{inaccessible default constructor}} |
Richard Smith | 1d0c9a8 | 2012-02-14 21:14:13 +0000 | [diff] [blame] | 51 | }; |
Douglas Gregor | e4e68d4 | 2012-02-15 19:33:52 +0000 | [diff] [blame] | 52 | int i = I().h.n; // expected-error {{call to implicitly-deleted default}} |
Richard Smith | 1d0c9a8 | 2012-02-14 21:14:13 +0000 | [diff] [blame] | 53 | |
| 54 | struct J { |
| 55 | J(); |
| 56 | virtual int f(); |
| 57 | int n; |
| 58 | }; |
| 59 | int j1 = J().n; // ok |
| 60 | int j2 = J().f(); // ok |
| 61 | |
Richard Smith | 6c4c36c | 2012-03-30 20:53:28 +0000 | [diff] [blame] | 62 | union K { |
| 63 | J j; // expected-note 2{{non-trivial default constructor}} |
Richard Smith | 1d0c9a8 | 2012-02-14 21:14:13 +0000 | [diff] [blame] | 64 | int m; |
| 65 | }; |
Douglas Gregor | e4e68d4 | 2012-02-15 19:33:52 +0000 | [diff] [blame] | 66 | int k1 = K().j.n; // expected-error {{call to implicitly-deleted default}} |
| 67 | int k2 = K().j.f(); // expected-error {{call to implicitly-deleted default}} |