blob: a12181d158d1fd5d439d5efc651ebb7c93ee5700 [file] [log] [blame]
Richard Smith762bb9d2011-10-13 22:29:44 +00001// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
Sebastian Redl6df65482011-09-24 17:48:25 +00002
Sebastian Redl5405b812011-10-16 18:19:34 +00003struct one { char c[1]; };
4struct two { char c[2]; };
5
Sebastian Redl6df65482011-09-24 17:48:25 +00006namespace 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 Redl5405b812011-10-16 18:19:34 +000037 void function_call() {
Sebastian Redld12c9f52011-10-16 18:19:11 +000038 void takes_int(int);
39 takes_int({1});
40 }
41
Sebastian Redl5405b812011-10-16 18:19:34 +000042 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 }
58
Sebastian Redl6df65482011-09-24 17:48:25 +000059}