Richard Smith | 762bb9d | 2011-10-13 22:29:44 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s |
Douglas Gregor | 64bffa9 | 2008-11-05 16:20:31 +0000 | [diff] [blame] | 2 | |
Sebastian Redl | 10f04a6 | 2011-12-22 14:44:04 +0000 | [diff] [blame] | 3 | // Verify that using an initializer list for a non-aggregate looks for |
| 4 | // constructors.. |
Richard Smith | 017ab77 | 2011-09-05 02:13:09 +0000 | [diff] [blame] | 5 | // Note that due to a (likely) standard bug, this is technically an aggregate, |
| 6 | // but we do not treat it as one. |
Sebastian Redl | 10f04a6 | 2011-12-22 14:44:04 +0000 | [diff] [blame] | 7 | struct NonAggr1 { // expected-note 2 {{candidate constructor}} |
| 8 | NonAggr1(int, int) { } // expected-note {{candidate constructor}} |
Douglas Gregor | 64bffa9 | 2008-11-05 16:20:31 +0000 | [diff] [blame] | 9 | |
| 10 | int m; |
| 11 | }; |
| 12 | |
| 13 | struct Base { }; |
Sebastian Redl | 10f04a6 | 2011-12-22 14:44:04 +0000 | [diff] [blame] | 14 | struct NonAggr2 : public Base { // expected-note 3 {{candidate constructor}} |
Douglas Gregor | 64bffa9 | 2008-11-05 16:20:31 +0000 | [diff] [blame] | 15 | int m; |
| 16 | }; |
| 17 | |
Sebastian Redl | 10f04a6 | 2011-12-22 14:44:04 +0000 | [diff] [blame] | 18 | class NonAggr3 { // expected-note 3 {{candidate constructor}} |
Douglas Gregor | 64bffa9 | 2008-11-05 16:20:31 +0000 | [diff] [blame] | 19 | int m; |
| 20 | }; |
| 21 | |
Sebastian Redl | 10f04a6 | 2011-12-22 14:44:04 +0000 | [diff] [blame] | 22 | struct NonAggr4 { // expected-note 3 {{candidate constructor}} |
Sebastian Redl | d93f0dd | 2008-11-06 15:59:35 +0000 | [diff] [blame] | 23 | int m; |
| 24 | virtual void f(); |
Douglas Gregor | 64bffa9 | 2008-11-05 16:20:31 +0000 | [diff] [blame] | 25 | }; |
| 26 | |
Sebastian Redl | 10f04a6 | 2011-12-22 14:44:04 +0000 | [diff] [blame] | 27 | NonAggr1 na1 = { 17 }; // expected-error{{no matching constructor for initialization of 'NonAggr1'}} |
| 28 | NonAggr2 na2 = { 17 }; // expected-error{{no matching constructor for initialization of 'NonAggr2'}} |
| 29 | NonAggr3 na3 = { 17 }; // expected-error{{no matching constructor for initialization of 'NonAggr3'}} |
| 30 | NonAggr4 na4 = { 17 }; // expected-error{{no matching constructor for initialization of 'NonAggr4'}} |
Douglas Gregor | bab497b | 2010-01-06 22:06:13 +0000 | [diff] [blame] | 31 | |
| 32 | // PR5817 |
| 33 | typedef int type[][2]; |
| 34 | const type foo = {0}; |
Anders Carlsson | 46f4659 | 2010-01-23 19:55:29 +0000 | [diff] [blame] | 35 | |
| 36 | // Vector initialization. |
| 37 | typedef short __v4hi __attribute__ ((__vector_size__ (8))); |
| 38 | __v4hi v1 = { (void *)1, 2, 3 }; // expected-error {{cannot initialize a vector element of type 'short' with an rvalue of type 'void *'}} |
Anders Carlsson | 784f699 | 2010-01-23 20:13:41 +0000 | [diff] [blame] | 39 | |
| 40 | // Array initialization. |
| 41 | int a[] = { (void *)1 }; // expected-error {{cannot initialize an array element of type 'int' with an rvalue of type 'void *'}} |
Anders Carlsson | 2bbae5d | 2010-01-23 20:20:40 +0000 | [diff] [blame] | 42 | |
| 43 | // Struct initialization. |
| 44 | struct S { int a; } s = { (void *)1 }; // expected-error {{cannot initialize a member subobject of type 'int' with an rvalue of type 'void *'}} |
Anders Carlsson | 1b36a2f | 2010-01-24 00:19:41 +0000 | [diff] [blame] | 45 | |
| 46 | // Check that we're copy-initializing the structs. |
| 47 | struct A { |
| 48 | A(); |
| 49 | A(int); |
| 50 | ~A(); |
Rafael Espindola | 12ce0a0 | 2011-07-14 22:58:04 +0000 | [diff] [blame] | 51 | |
| 52 | A(const A&) = delete; // expected-note 2 {{function has been explicitly marked deleted here}} |
Anders Carlsson | 1b36a2f | 2010-01-24 00:19:41 +0000 | [diff] [blame] | 53 | }; |
| 54 | |
| 55 | struct B { |
| 56 | A a; |
| 57 | }; |
| 58 | |
| 59 | struct C { |
| 60 | const A& a; |
| 61 | }; |
| 62 | |
| 63 | void f() { |
| 64 | A as1[1] = { }; |
Rafael Espindola | 12ce0a0 | 2011-07-14 22:58:04 +0000 | [diff] [blame] | 65 | A as2[1] = { 1 }; // expected-error {{copying array element of type 'A' invokes deleted constructor}} |
Anders Carlsson | 1b36a2f | 2010-01-24 00:19:41 +0000 | [diff] [blame] | 66 | |
| 67 | B b1 = { }; |
Rafael Espindola | 12ce0a0 | 2011-07-14 22:58:04 +0000 | [diff] [blame] | 68 | B b2 = { 1 }; // expected-error {{copying member subobject of type 'A' invokes deleted constructor}} |
Anders Carlsson | 1b36a2f | 2010-01-24 00:19:41 +0000 | [diff] [blame] | 69 | |
| 70 | C c1 = { 1 }; |
| 71 | } |
Douglas Gregor | fb87b89 | 2010-04-26 21:31:17 +0000 | [diff] [blame] | 72 | |
| 73 | class Agg { |
| 74 | public: |
| 75 | int i, j; |
| 76 | }; |
| 77 | |
| 78 | class AggAgg { |
| 79 | public: |
| 80 | Agg agg1; |
| 81 | Agg agg2; |
| 82 | }; |
| 83 | |
| 84 | AggAgg aggagg = { 1, 2, 3, 4 }; |