blob: ea2db0c68e8580278a14d884cc2c0aae9422eff5 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
Douglas Gregorf03d7c72008-11-05 15:29:30 +00002class X {
3public:
Douglas Gregor153b3ba2010-04-18 02:16:12 +00004 explicit X(const X&); // expected-note {{candidate constructor}}
5 X(int*); // expected-note 3{{candidate constructor}}
6 explicit X(float*); // expected-note {{candidate constructor}}
Douglas Gregorf03d7c72008-11-05 15:29:30 +00007};
8
9class Y : public X { };
10
11void f(Y y, int *ip, float *fp) {
John McCall7c2342d2010-03-10 11:27:22 +000012 X x1 = y; // expected-error{{no matching constructor for initialization of 'X'}}
Douglas Gregor8ff338b2010-11-12 03:34:06 +000013 X x2 = 0;
14 X x3 = ip;
Douglas Gregor7abfbdb2009-12-19 03:01:41 +000015 X x4 = fp; // expected-error{{no viable conversion}}
Douglas Gregor153b3ba2010-04-18 02:16:12 +000016 X x2a(0); // expected-error{{call to constructor of 'X' is ambiguous}}
17 X x3a(ip);
18 X x4a(fp);
Douglas Gregorf03d7c72008-11-05 15:29:30 +000019}
Douglas Gregor611a8c42009-02-19 00:52:42 +000020
21struct foo {
Argyrios Kyrtzidis64ccf242010-11-16 08:04:45 +000022 void bar(); // expected-note{{declared here}}
Douglas Gregor611a8c42009-02-19 00:52:42 +000023};
24
25// PR3600
Argyrios Kyrtzidis64ccf242010-11-16 08:04:45 +000026void test(const foo *P) { P->bar(); } // expected-error{{'bar' not viable: 'this' argument has type 'const foo', but function is not marked const}}
Douglas Gregor2f599792010-04-02 18:24:57 +000027
28namespace PR6757 {
29 struct Foo {
30 Foo();
Douglas Gregor3fbaf3e2010-04-17 22:01:05 +000031 Foo(Foo&); // expected-note{{candidate constructor not viable}}
Douglas Gregor2f599792010-04-02 18:24:57 +000032 };
33
34 struct Bar {
35 operator const Foo&() const;
36 };
37
Douglas Gregor3fbaf3e2010-04-17 22:01:05 +000038 void f(Foo);
Douglas Gregor2f599792010-04-02 18:24:57 +000039
Douglas Gregor2f599792010-04-02 18:24:57 +000040 void g(Foo foo) {
Chris Lattner0c42bb62010-09-05 00:17:29 +000041 f(Bar()); // expected-error{{no viable constructor copying parameter of type 'const PR6757::Foo'}}
Douglas Gregor2f599792010-04-02 18:24:57 +000042 f(foo);
43 }
44}
Richard Smithf2e4dfc2012-02-11 19:22:50 +000045
46namespace DR5 {
47 // Core issue 5: if a temporary is created in copy-initialization, it is of
48 // the cv-unqualified version of the destination type.
49 namespace Ex1 {
50 struct C { };
51 C c;
52 struct A {
53 A(const A&);
54 A(const C&);
55 };
56 const volatile A a = c; // ok
57 }
58
59 namespace Ex2 {
60 struct S {
61 S(S&&); // expected-warning {{C++11}}
62 S(int);
63 };
64 const S a(0);
65 const S b = 0;
66 }
67}