Richard Smith | 2fbb3d8 | 2012-02-26 23:49:01 +0000 | [diff] [blame] | 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 | |
Richard Smith | 2fbb3d8 | 2012-02-26 23:49:01 +0000 | [diff] [blame] | 14 | int a, b; |
Sebastian Redl | 6776673 | 2012-02-27 20:34:02 +0000 | [diff] [blame] | 15 | a = b = { 1 }; |
Richard Smith | 5e0cac7 | 2012-03-01 02:59:17 +0000 | [diff] [blame] | 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 '*'}} |
Richard Smith | 2fbb3d8 | 2012-02-26 23:49:01 +0000 | [diff] [blame] | 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) { return s.a; } |
| 28 | constexpr int operator+=(S s) { return s.b; } |
| 29 | }; |
| 30 | static_assert((T() = {4, 9}) == 4, ""); |
| 31 | static_assert((T() += {4, 9}) == 9, ""); |
| 32 | |
Richard Smith | 5e0cac7 | 2012-03-01 02:59:17 +0000 | [diff] [blame] | 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 '+'}} |