| Richard Smith | 9ca5c42 | 2011-10-13 22:29:44 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s | 
| Sebastian Redl | a74948d | 2011-09-24 17:48:25 +0000 | [diff] [blame] | 2 |  | 
| Sebastian Redl | b17be8d | 2011-10-16 18:19:34 +0000 | [diff] [blame] | 3 | struct one { char c[1]; }; | 
|  | 4 | struct two { char c[2]; }; | 
|  | 5 |  | 
| Sebastian Redl | a74948d | 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}} | 
|  | 18 | } | 
|  | 19 |  | 
|  | 20 | int direct_usage() { | 
|  | 21 | int ar[10]; | 
|  | 22 | (void) ar[{1}]; // expected-error {{array subscript is not an integer}} | 
|  | 23 |  | 
|  | 24 | return {1}; | 
|  | 25 | } | 
|  | 26 |  | 
|  | 27 | void inline_init() { | 
|  | 28 | (void) int{1}; | 
|  | 29 | (void) new int{1}; | 
|  | 30 | } | 
|  | 31 |  | 
|  | 32 | struct A { | 
|  | 33 | int i; | 
|  | 34 | A() : i{1} {} | 
|  | 35 | }; | 
|  | 36 |  | 
| Sebastian Redl | b17be8d | 2011-10-16 18:19:34 +0000 | [diff] [blame] | 37 | void function_call() { | 
| Sebastian Redl | b92a877 | 2011-10-16 18:19:11 +0000 | [diff] [blame] | 38 | void takes_int(int); | 
|  | 39 | takes_int({1}); | 
|  | 40 | } | 
|  | 41 |  | 
| Sebastian Redl | b17be8d | 2011-10-16 18:19:34 +0000 | [diff] [blame] | 42 | void overloaded_call() { | 
|  | 43 | one overloaded(int); | 
|  | 44 | two overloaded(double); | 
|  | 45 |  | 
|  | 46 | static_assert(sizeof(overloaded({0})) == sizeof(one), "bad overload"); | 
|  | 47 | static_assert(sizeof(overloaded({0.0})) == sizeof(two), "bad overload"); | 
|  | 48 |  | 
|  | 49 | void ambiguous(int, double); // expected-note {{candidate}} | 
|  | 50 | void ambiguous(double, int); // expected-note {{candidate}} | 
|  | 51 | ambiguous({0}, {0}); // expected-error {{ambiguous}} | 
|  | 52 |  | 
|  | 53 | void emptylist(int); | 
|  | 54 | void emptylist(int, int, int); | 
|  | 55 | emptylist({}); | 
|  | 56 | emptylist({}, {}, {}); | 
|  | 57 | } | 
| Sebastian Redl | a74948d | 2011-09-24 17:48:25 +0000 | [diff] [blame] | 58 | } |