1 | // RUN: %clang_cc1 -verify -std=c++11 %s |
2 | |
3 | template<typename T> struct complex { |
4 | complex(T = T(), T = T()); |
5 | void operator+=(complex); |
6 | T a, b; |
7 | }; |
8 | |
9 | void std_example() { |
10 | complex<double> z; |
11 | z = { 1, 2 }; |
12 | z += { 1, 2 }; |
13 | |
14 | int a, b; |
15 | a = b = { 1 }; |
16 | 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 '*'}} |
20 | } |
21 | |
22 | struct S { |
23 | constexpr S(int a, int b) : a(a), b(b) {} |
24 | int a, b; |
25 | }; |
26 | struct T { |
27 | constexpr int operator=(S s) const { return s.a; } |
28 | constexpr int operator+=(S s) const { return s.b; } |
29 | }; |
30 | static_assert((T() = {4, 9}) == 4, ""); |
31 | static_assert((T() += {4, 9}) == 9, ""); |
32 | |
33 | int k1 = T() = { 1, 2 } = { 3, 4 }; // expected-error {{initializer list cannot be used on the left hand side of operator '='}} |
34 | int k2 = T() = { 1, 2 } + 1; // expected-error {{initializer list cannot be used on the left hand side of operator '+'}} |
35 | |