Richard Smith | 762bb9d | 2011-10-13 22:29:44 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s |
Sebastian Redl | 6df6548 | 2011-09-24 17:48:25 +0000 | [diff] [blame] | 2 | |
Sebastian Redl | 5405b81 | 2011-10-16 18:19:34 +0000 | [diff] [blame] | 3 | struct one { char c[1]; }; |
| 4 | struct two { char c[2]; }; |
| 5 | |
Sebastian Redl | 6df6548 | 2011-09-24 17:48:25 +0000 | [diff] [blame] | 6 | namespace integral { |
| 7 | |
| 8 | void initialization() { |
| 9 | { const int a{}; static_assert(a == 0, ""); } |
| 10 | { const int a = {}; static_assert(a == 0, ""); } |
| 11 | { const int a{1}; static_assert(a == 1, ""); } |
| 12 | { const int a = {1}; static_assert(a == 1, ""); } |
| 13 | { const int a{1, 2}; } // expected-error {{excess elements}} |
| 14 | { const int a = {1, 2}; } // expected-error {{excess elements}} |
| 15 | // FIXME: Redundant warnings. |
| 16 | { const short a{100000}; } // expected-error {{cannot be narrowed}} expected-note {{inserting an explicit cast}} expected-warning {{changes value}} |
| 17 | { const short a = {100000}; } // expected-error {{cannot be narrowed}} expected-note {{inserting an explicit cast}} expected-warning {{changes value}} |
Richard Smith | 0635aa7 | 2012-02-22 06:49:09 +0000 | [diff] [blame] | 18 | { if (const int a{1}) static_assert(a == 1, ""); } |
| 19 | { if (const int a = {1}) static_assert(a == 1, ""); } |
Sebastian Redl | 6df6548 | 2011-09-24 17:48:25 +0000 | [diff] [blame] | 20 | } |
| 21 | |
| 22 | int direct_usage() { |
| 23 | int ar[10]; |
| 24 | (void) ar[{1}]; // expected-error {{array subscript is not an integer}} |
| 25 | |
| 26 | return {1}; |
| 27 | } |
| 28 | |
| 29 | void inline_init() { |
Sebastian Redl | 6dc00f6 | 2012-02-12 18:41:05 +0000 | [diff] [blame] | 30 | auto v = int{1}; |
Sebastian Redl | 6df6548 | 2011-09-24 17:48:25 +0000 | [diff] [blame] | 31 | (void) new int{1}; |
| 32 | } |
| 33 | |
| 34 | struct A { |
| 35 | int i; |
| 36 | A() : i{1} {} |
| 37 | }; |
| 38 | |
Sebastian Redl | 5405b81 | 2011-10-16 18:19:34 +0000 | [diff] [blame] | 39 | void function_call() { |
Sebastian Redl | d12c9f5 | 2011-10-16 18:19:11 +0000 | [diff] [blame] | 40 | void takes_int(int); |
| 41 | takes_int({1}); |
| 42 | } |
| 43 | |
Sebastian Redl | 5405b81 | 2011-10-16 18:19:34 +0000 | [diff] [blame] | 44 | void overloaded_call() { |
| 45 | one overloaded(int); |
| 46 | two overloaded(double); |
| 47 | |
| 48 | static_assert(sizeof(overloaded({0})) == sizeof(one), "bad overload"); |
| 49 | static_assert(sizeof(overloaded({0.0})) == sizeof(two), "bad overload"); |
| 50 | |
| 51 | void ambiguous(int, double); // expected-note {{candidate}} |
| 52 | void ambiguous(double, int); // expected-note {{candidate}} |
| 53 | ambiguous({0}, {0}); // expected-error {{ambiguous}} |
| 54 | |
| 55 | void emptylist(int); |
| 56 | void emptylist(int, int, int); |
| 57 | emptylist({}); |
| 58 | emptylist({}, {}, {}); |
| 59 | } |
Sebastian Redl | 3a45c0e | 2012-02-12 16:37:36 +0000 | [diff] [blame] | 60 | |
| 61 | void edge_cases() { |
| 62 | // FIXME: very poor error message |
| 63 | int a({0}); // expected-error {{cannot initialize}} |
Sebastian Redl | 6dc00f6 | 2012-02-12 18:41:05 +0000 | [diff] [blame] | 64 | (void) int({0}); // expected-error {{functional-style cast}} |
| 65 | new int({0}); // expected-error {{cannot initialize}} |
Sebastian Redl | 3a45c0e | 2012-02-12 16:37:36 +0000 | [diff] [blame] | 66 | } |
Sebastian Redl | 6df6548 | 2011-09-24 17:48:25 +0000 | [diff] [blame] | 67 | } |