xref: /minix3/external/bsd/llvm/dist/clang/test/SemaCXX/converting-constructor.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify %s
2*f4a2713aSLionel Sambuc class Z { };
3*f4a2713aSLionel Sambuc 
4*f4a2713aSLionel Sambuc class Y {
5*f4a2713aSLionel Sambuc public:
6*f4a2713aSLionel Sambuc   Y(const Z&);
7*f4a2713aSLionel Sambuc };
8*f4a2713aSLionel Sambuc 
9*f4a2713aSLionel Sambuc class X {
10*f4a2713aSLionel Sambuc public:
11*f4a2713aSLionel Sambuc   X(int);
12*f4a2713aSLionel Sambuc   X(const Y&);
13*f4a2713aSLionel Sambuc };
14*f4a2713aSLionel Sambuc 
15*f4a2713aSLionel Sambuc void f(X); // expected-note{{candidate function}}
16*f4a2713aSLionel Sambuc 
g(short s,Y y,Z z)17*f4a2713aSLionel Sambuc void g(short s, Y y, Z z) {
18*f4a2713aSLionel Sambuc   f(s);
19*f4a2713aSLionel Sambuc   f(1.0f);
20*f4a2713aSLionel Sambuc   f(y);
21*f4a2713aSLionel Sambuc   f(z); // expected-error{{no matching function}}
22*f4a2713aSLionel Sambuc }
23*f4a2713aSLionel Sambuc 
24*f4a2713aSLionel Sambuc 
25*f4a2713aSLionel Sambuc class FromShort {
26*f4a2713aSLionel Sambuc public:
27*f4a2713aSLionel Sambuc   FromShort(short s);
28*f4a2713aSLionel Sambuc };
29*f4a2713aSLionel Sambuc 
30*f4a2713aSLionel Sambuc class FromShortExplicitly { // expected-note{{candidate constructor (the implicit copy constructor)}}
31*f4a2713aSLionel Sambuc public:
32*f4a2713aSLionel Sambuc   explicit FromShortExplicitly(short s);
33*f4a2713aSLionel Sambuc };
34*f4a2713aSLionel Sambuc 
explicit_constructor(short s)35*f4a2713aSLionel Sambuc void explicit_constructor(short s) {
36*f4a2713aSLionel Sambuc   FromShort fs1(s);
37*f4a2713aSLionel Sambuc   FromShort fs2 = s;
38*f4a2713aSLionel Sambuc   FromShortExplicitly fse1(s);
39*f4a2713aSLionel Sambuc   FromShortExplicitly fse2 = s; // expected-error{{no viable conversion}}
40*f4a2713aSLionel Sambuc }
41*f4a2713aSLionel Sambuc 
42*f4a2713aSLionel Sambuc // PR5519
43*f4a2713aSLionel Sambuc struct X1 { X1(const char&); };
44*f4a2713aSLionel Sambuc void x1(X1);
y1()45*f4a2713aSLionel Sambuc void y1() {
46*f4a2713aSLionel Sambuc   x1(1);
47*f4a2713aSLionel Sambuc }
48