blob: c0833668657edc65fbacc933a92a8a1612d09a37 [file] [log] [blame]
Sebastian Redl10f04a62011-12-22 14:44:04 +00001// RUN: %clang_cc1 -std=c++0x -fsyntax-only -verify %s
2
Sebastian Redlcf15cef2011-12-22 18:58:38 +00003struct one { char c[1]; };
4struct two { char c[2]; };
5
Sebastian Redl10f04a62011-12-22 14:44:04 +00006namespace objects {
7
8 struct X1 { X1(int); };
9 struct X2 { explicit X2(int); }; // expected-note 2 {{candidate constructor}}
10
11 template <int N>
12 struct A {
13 A() { static_assert(N == 0, ""); }
14 A(int, double) { static_assert(N == 1, ""); }
15 };
16
17 template <int N>
18 struct E {
19 E(int, int) { static_assert(N == 0, ""); }
20 E(X1, int) { static_assert(N == 1, ""); }
21 };
22
23 void overload_resolution() {
24 { A<0> a{}; }
25 { A<0> a = {}; }
26 { A<1> a{1, 1.0}; }
27 { A<1> a = {1, 1.0}; }
28
29 { E<0> e{1, 2}; }
30 }
31
32 void explicit_implicit() {
33 { X1 x{0}; }
34 { X1 x = {0}; }
35 { X2 x{0}; }
36 { X2 x = {0}; } // expected-error {{no matching constructor}}
37 }
38
39 struct C {
40 C();
41 C(int, double);
42 C(int, int);
43
44 int operator[](C);
45 };
46
47 C function_call() {
48 void takes_C(C);
49 takes_C({1, 1.0});
50
Sebastian Redlcf15cef2011-12-22 18:58:38 +000051 C c;
52 c[{1, 1.0}];
Sebastian Redl10f04a62011-12-22 14:44:04 +000053
54 return {1, 1.0};
55 }
56
57 void inline_init() {
Sebastian Redl62f13c92011-12-22 18:58:29 +000058 (void) C{1, 1.0};
Sebastian Redl10f04a62011-12-22 14:44:04 +000059 (void) new C{1, 1.0};
60 }
61
Sebastian Redlcf15cef2011-12-22 18:58:38 +000062 struct B { // expected-note 2 {{candidate constructor}}
63 B(C, int, C); // expected-note {{candidate constructor not viable: cannot convert initializer list argument to 'objects::C'}}
Sebastian Redl10f04a62011-12-22 14:44:04 +000064 };
65
66 void nested_init() {
Sebastian Redlcf15cef2011-12-22 18:58:38 +000067 B b1{{1, 1.0}, 2, {3, 4}};
68 B b2{{1, 1.0, 4}, 2, {3, 4}}; // expected-error {{no matching constructor for initialization of 'objects::B'}}
69 }
70
71 void overloaded_call() {
72 one ov1(B); // expected-note {{not viable: cannot convert initializer list}}
73 two ov1(C); // expected-note {{not viable: cannot convert initializer list}}
74
75 static_assert(sizeof(ov1({})) == sizeof(two), "bad overload");
76 static_assert(sizeof(ov1({1, 2})) == sizeof(two), "bad overload");
77 static_assert(sizeof(ov1({{1, 1.0}, 2, {3, 4}})) == sizeof(one), "bad overload");
78
79 ov1({1}); // expected-error {{no matching function}}
Sebastian Redl10f04a62011-12-22 14:44:04 +000080 }
81}