1 // RUN: %clang_cc1 -std=c++0x -fsyntax-only -verify %s
2 
3 struct one { char c[1]; };
4 struct two { char c[2]; };
5 
6 namespace 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 
51     C c;
52     c[{1, 1.0}];
53 
54     return {1, 1.0};
55   }
56 
57   void inline_init() {
58     (void) C{1, 1.0};
59     (void) new C{1, 1.0};
60   }
61 
62   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'}}
64   };
65 
66   void nested_init() {
67     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}}
80   }
81 }
82