1 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
3 struct one { char c; };
4 struct two { char c[2]; };
12 const int &cri1a = {1};
19 int &ri2 = {1}; // expected-error {{cannot bind to an initializer list temporary}}
26 void reference_to_aggregate() {
28 A &ra2{1, 2}; // expected-error {{cannot bind to an initializer list temporary}}
30 const int (&arrayRef)[] = {1, 2, 3};
31 static_assert(sizeof(arrayRef) == 3 * sizeof(int), "bad array size");
42 one g(int&); // expected-note {{passing argument}}
43 g({1}); // expected-error {{cannot bind to an initializer list temporary}}
50 void a(B&); // expected-note {{passing argument}}
51 a({1}); // expected-error {{cannot bind to an initializer list temporary}}
60 // First is identity conversion, second is user-defined conversion.
61 static_assert(sizeof(f({1})) == sizeof(one), "bad overload resolution");
66 static_assert(sizeof(g({1})) == sizeof(two), "bad overload resolution");
71 static_assert(sizeof(h({1, 2})) == sizeof(two), "bad overload resolution");
75 // FIXME: very poor error message
76 int const &b({0}); // expected-error {{could not bind}}
82 void f(int const(&)[3]);
91 struct S { S(int); } const &s { 2 };
95 typedef void (*ptr)();
96 template <class T> void f();
98 int k = g({ f<int> });
101 namespace inner_init {
104 B b1 { 0 }; // expected-error {{reference to type 'inner_init::A' could not bind to an rvalue of type 'int'}}
106 B b3 { { { 0 } } }; // expected-warning {{braces around scalar init}}
108 struct C { C(int); }; // expected-note 2{{candidate constructor (the implicit}} \
109 // expected-note {{candidate constructor not viable: cannot convert initializer list argument to 'int'}}
111 D d1 { 0 }; // ok, 0 implicitly converts to C
112 D d2 { { 0 } }; // ok, { 0 } calls C(0)
113 D d3 { { { 0 } } }; // ok, { { 0 } } calls C({ 0 }), expected-warning {{braces around scalar init}}
114 D d4 { { { { 0 } } } }; // expected-error {{no matching constructor for initialization of 'inner_init::C &&'}}
116 struct E { explicit E(int); }; // expected-note 2{{here}}
118 F f1 { 0 }; // expected-error {{could not bind to an rvalue of type 'int'}}
119 F f2 { { 0 } }; // expected-error {{chosen constructor is explicit}}
120 F f3 { { { 0 } } }; // expected-error {{chosen constructor is explicit}}
125 struct B { operator A&(); } b;
126 A &a{b}; // expected-error {{excess elements}} expected-note {{in initialization of temporary of type 'PR20844::A'}}
130 const int &a = (const int &){0}; // expected-error {{cannot bind to an initializer list}}