blob: 8d25443da8accb571db010b87e2f8ffa86af4657 [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}}
Richard Smith0635aa72012-02-22 06:49:09 +000018 { if (const int a{1}) static_assert(a == 1, ""); }
19 { if (const int a = {1}) static_assert(a == 1, ""); }
Sebastian Redl6df65482011-09-24 17:48:25 +000020 }
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 Redl6dc00f62012-02-12 18:41:05 +000030 auto v = int{1};
Sebastian Redl6df65482011-09-24 17:48:25 +000031 (void) new int{1};
32 }
33
34 struct A {
35 int i;
36 A() : i{1} {}
37 };
38
Sebastian Redl5405b812011-10-16 18:19:34 +000039 void function_call() {
Sebastian Redld12c9f52011-10-16 18:19:11 +000040 void takes_int(int);
41 takes_int({1});
42 }
43
Sebastian Redl5405b812011-10-16 18:19:34 +000044 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 Redl3a45c0e2012-02-12 16:37:36 +000060
61 void edge_cases() {
62 // FIXME: very poor error message
63 int a({0}); // expected-error {{cannot initialize}}
Sebastian Redl6dc00f62012-02-12 18:41:05 +000064 (void) int({0}); // expected-error {{functional-style cast}}
65 new int({0}); // expected-error {{cannot initialize}}
Sebastian Redl3a45c0e2012-02-12 16:37:36 +000066 }
Sebastian Redl6df65482011-09-24 17:48:25 +000067}