blob: 206c82c985c74d367bf98abf6e8b59ef3aa4c5f2 [file] [log] [blame]
Richard Smith2fbb3d82012-02-26 23:49:01 +00001// RUN: %clang_cc1 -verify -std=c++11 %s
2
3template<typename T> struct complex {
4 complex(T = T(), T = T());
5 void operator+=(complex);
6 T a, b;
7};
8
9void std_example() {
10 complex<double> z;
11 z = { 1, 2 };
12 z += { 1, 2 };
13
Richard Smith2fbb3d82012-02-26 23:49:01 +000014 int a, b;
Sebastian Redl67766732012-02-27 20:34:02 +000015 a = b = { 1 };
Richard Smith5e0cac72012-03-01 02:59:17 +000016 a = { 1 } = b; // expected-error {{initializer list cannot be used on the left hand side of operator '='}}
17 a = a + { 4 }; // expected-error {{initializer list cannot be used on the right hand side of operator '+'}}
18 a = { 3 } * { 4 }; // expected-error {{initializer list cannot be used on the left hand side of operator '*'}} \
19 expected-error {{initializer list cannot be used on the right hand side of operator '*'}}
Richard Smith2fbb3d82012-02-26 23:49:01 +000020}
21
22struct S {
23 constexpr S(int a, int b) : a(a), b(b) {}
24 int a, b;
25};
26struct T {
27 constexpr int operator=(S s) { return s.a; }
28 constexpr int operator+=(S s) { return s.b; }
29};
30static_assert((T() = {4, 9}) == 4, "");
31static_assert((T() += {4, 9}) == 9, "");
32
Richard Smith5e0cac72012-03-01 02:59:17 +000033int k1 = T() = { 1, 2 } = { 3, 4 }; // expected-error {{initializer list cannot be used on the left hand side of operator '='}}
34int k2 = T() = { 1, 2 } + 1; // expected-error {{initializer list cannot be used on the left hand side of operator '+'}}