blob: 3c0e4483c441f7b0bf4e560be842262f49ef38f0 [file] [log] [blame]
Richard Smith762bb9d2011-10-13 22:29:44 +00001// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
Douglas Gregor64bffa92008-11-05 16:20:31 +00002
3// Verify that we can't initialize non-aggregates with an initializer
4// list.
Richard Smith017ab772011-09-05 02:13:09 +00005// Note that due to a (likely) standard bug, this is technically an aggregate,
6// but we do not treat it as one.
Douglas Gregor64bffa92008-11-05 16:20:31 +00007struct NonAggr1 {
8 NonAggr1(int) { }
9
10 int m;
11};
12
13struct Base { };
14struct NonAggr2 : public Base {
15 int m;
16};
17
18class NonAggr3 {
19 int m;
20};
21
Douglas Gregor64bffa92008-11-05 16:20:31 +000022struct NonAggr4 {
Sebastian Redld93f0dd2008-11-06 15:59:35 +000023 int m;
24 virtual void f();
Douglas Gregor64bffa92008-11-05 16:20:31 +000025};
26
Richard Smith017ab772011-09-05 02:13:09 +000027NonAggr1 na1 = { 17 }; // expected-error{{non-aggregate type 'NonAggr1' cannot be initialized with an initializer list}}
John McCall7c2342d2010-03-10 11:27:22 +000028NonAggr2 na2 = { 17 }; // expected-error{{non-aggregate type 'NonAggr2' cannot be initialized with an initializer list}}
29NonAggr3 na3 = { 17 }; // expected-error{{non-aggregate type 'NonAggr3' cannot be initialized with an initializer list}}
30NonAggr4 na4 = { 17 }; // expected-error{{non-aggregate type 'NonAggr4' cannot be initialized with an initializer list}}
Douglas Gregorbab497b2010-01-06 22:06:13 +000031
32// PR5817
33typedef int type[][2];
34const type foo = {0};
Anders Carlsson46f46592010-01-23 19:55:29 +000035
36// Vector initialization.
37typedef 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 Carlsson784f6992010-01-23 20:13:41 +000039
40// Array initialization.
41int a[] = { (void *)1 }; // expected-error {{cannot initialize an array element of type 'int' with an rvalue of type 'void *'}}
Anders Carlsson2bbae5d2010-01-23 20:20:40 +000042
43// Struct initialization.
44struct S { int a; } s = { (void *)1 }; // expected-error {{cannot initialize a member subobject of type 'int' with an rvalue of type 'void *'}}
Anders Carlsson1b36a2f2010-01-24 00:19:41 +000045
46// Check that we're copy-initializing the structs.
47struct A {
48 A();
49 A(int);
50 ~A();
Rafael Espindola12ce0a02011-07-14 22:58:04 +000051
52 A(const A&) = delete; // expected-note 2 {{function has been explicitly marked deleted here}}
Anders Carlsson1b36a2f2010-01-24 00:19:41 +000053};
54
55struct B {
56 A a;
57};
58
59struct C {
60 const A& a;
61};
62
63void f() {
64 A as1[1] = { };
Rafael Espindola12ce0a02011-07-14 22:58:04 +000065 A as2[1] = { 1 }; // expected-error {{copying array element of type 'A' invokes deleted constructor}}
Anders Carlsson1b36a2f2010-01-24 00:19:41 +000066
67 B b1 = { };
Rafael Espindola12ce0a02011-07-14 22:58:04 +000068 B b2 = { 1 }; // expected-error {{copying member subobject of type 'A' invokes deleted constructor}}
Anders Carlsson1b36a2f2010-01-24 00:19:41 +000069
70 C c1 = { 1 };
71}
Douglas Gregorfb87b892010-04-26 21:31:17 +000072
73class Agg {
74public:
75 int i, j;
76};
77
78class AggAgg {
79public:
80 Agg agg1;
81 Agg agg2;
82};
83
84AggAgg aggagg = { 1, 2, 3, 4 };