Sebastian Redl | c223518 | 2011-10-16 18:19:28 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -std=c++0x -fsyntax-only -verify %s |
| 2 | |
Sebastian Redl | cc7a648 | 2011-11-01 15:53:09 +0000 | [diff] [blame^] | 3 | struct one { char c[1]; }; |
| 4 | struct two { char c[2]; }; |
| 5 | |
Sebastian Redl | c223518 | 2011-10-16 18:19:28 +0000 | [diff] [blame] | 6 | namespace aggregate { |
| 7 | // Direct list initialization does NOT allow braces to be elided! |
| 8 | struct S { |
| 9 | int ar[2]; |
| 10 | struct T { |
| 11 | int i1; |
| 12 | int i2; |
| 13 | } t; |
| 14 | struct U { |
| 15 | int i1; |
| 16 | } u[2]; |
| 17 | struct V { |
| 18 | int var[2]; |
| 19 | } v; |
| 20 | }; |
| 21 | |
Sebastian Redl | cc7a648 | 2011-11-01 15:53:09 +0000 | [diff] [blame^] | 22 | void bracing() { |
Sebastian Redl | c223518 | 2011-10-16 18:19:28 +0000 | [diff] [blame] | 23 | S s1 = { 1, 2, 3 ,4, 5, 6, 7, 8 }; // no-error |
| 24 | S s2{ {1, 2}, {3, 4}, { {5}, {6} }, { {7, 8} } }; // completely braced |
| 25 | S s3{ 1, 2, 3, 4, 5, 6 }; // expected-error 5 {{cannot omit braces}} |
| 26 | S s4{ {1, 2}, {3, 4}, {5, 6}, { {7, 8} } }; // expected-error 2 {{cannot omit braces}} |
| 27 | S s5{ {1, 2}, {3, 4}, { {5}, {6} }, {7, 8} }; // expected-error {{cannot omit braces}} |
| 28 | } |
Sebastian Redl | cc7a648 | 2011-11-01 15:53:09 +0000 | [diff] [blame^] | 29 | |
| 30 | struct String { |
| 31 | String(const char*); |
| 32 | }; |
| 33 | |
| 34 | struct A { |
| 35 | int m1; |
| 36 | int m2; |
| 37 | }; |
| 38 | |
| 39 | void function_call() { |
| 40 | void takes_A(A); |
| 41 | takes_A({1, 2}); |
| 42 | } |
| 43 | |
| 44 | struct B { |
| 45 | int m1; |
| 46 | String m2; |
| 47 | }; |
| 48 | |
| 49 | void overloaded_call() { |
| 50 | one overloaded(A); |
| 51 | two overloaded(B); |
| 52 | |
| 53 | static_assert(sizeof(overloaded({1, 2})) == sizeof(one), "bad overload"); |
| 54 | static_assert(sizeof(overloaded({1, "two"})) == sizeof(two), |
| 55 | "bad overload"); |
| 56 | // String is not default-constructible |
| 57 | static_assert(sizeof(overloaded({1})) == sizeof(one), "bad overload"); |
| 58 | } |
Sebastian Redl | c223518 | 2011-10-16 18:19:28 +0000 | [diff] [blame] | 59 | } |