blob: 4f6c65cf550c80c32b4212245544aa17e8a5a820 [file] [log] [blame]
Daniel Dunbar8fbe78f2009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
Charles Li542f04c2015-11-11 19:34:47 +00002// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
3// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
4
Douglas Gregor6f543152008-11-05 15:29:30 +00005class X {
6public:
Douglas Gregor7566e4a2010-04-18 02:16:12 +00007 explicit X(const X&); // expected-note {{candidate constructor}}
8 X(int*); // expected-note 3{{candidate constructor}}
9 explicit X(float*); // expected-note {{candidate constructor}}
Douglas Gregor6f543152008-11-05 15:29:30 +000010};
11
12class Y : public X { };
13
14void f(Y y, int *ip, float *fp) {
John McCall85f90552010-03-10 11:27:22 +000015 X x1 = y; // expected-error{{no matching constructor for initialization of 'X'}}
Douglas Gregorcbd07102010-11-12 03:34:06 +000016 X x2 = 0;
17 X x3 = ip;
Douglas Gregora4b592a2009-12-19 03:01:41 +000018 X x4 = fp; // expected-error{{no viable conversion}}
Douglas Gregor7566e4a2010-04-18 02:16:12 +000019 X x2a(0); // expected-error{{call to constructor of 'X' is ambiguous}}
20 X x3a(ip);
21 X x4a(fp);
Douglas Gregor6f543152008-11-05 15:29:30 +000022}
Douglas Gregor0f3dd9a2009-02-19 00:52:42 +000023
24struct foo {
Argyrios Kyrtzidis9813d322010-11-16 08:04:45 +000025 void bar(); // expected-note{{declared here}}
Douglas Gregor0f3dd9a2009-02-19 00:52:42 +000026};
27
28// PR3600
Argyrios Kyrtzidis9813d322010-11-16 08:04:45 +000029void test(const foo *P) { P->bar(); } // expected-error{{'bar' not viable: 'this' argument has type 'const foo', but function is not marked const}}
Douglas Gregor45cf7e32010-04-02 18:24:57 +000030
31namespace PR6757 {
32 struct Foo {
Richard Smith7c2bcc92016-09-07 02:14:33 +000033 Foo(); // expected-note{{not viable}}
Douglas Gregor5ab11652010-04-17 22:01:05 +000034 Foo(Foo&); // expected-note{{candidate constructor not viable}}
Douglas Gregor45cf7e32010-04-02 18:24:57 +000035 };
36
37 struct Bar {
38 operator const Foo&() const;
39 };
40
Douglas Gregor5ab11652010-04-17 22:01:05 +000041 void f(Foo);
Douglas Gregor45cf7e32010-04-02 18:24:57 +000042
Douglas Gregor45cf7e32010-04-02 18:24:57 +000043 void g(Foo foo) {
Chris Lattner24b89462010-09-05 00:17:29 +000044 f(Bar()); // expected-error{{no viable constructor copying parameter of type 'const PR6757::Foo'}}
Douglas Gregor45cf7e32010-04-02 18:24:57 +000045 f(foo);
46 }
47}
Richard Smithb24f0672012-02-11 19:22:50 +000048
49namespace DR5 {
50 // Core issue 5: if a temporary is created in copy-initialization, it is of
51 // the cv-unqualified version of the destination type.
52 namespace Ex1 {
53 struct C { };
54 C c;
55 struct A {
56 A(const A&);
57 A(const C&);
58 };
59 const volatile A a = c; // ok
60 }
61
62 namespace Ex2 {
63 struct S {
Charles Li542f04c2015-11-11 19:34:47 +000064 S(S&&);
65#if __cplusplus <= 199711L // C++03 or earlier modes
66 // expected-warning@-2 {{rvalue references are a C++11 extension}}
67#endif
Richard Smithb24f0672012-02-11 19:22:50 +000068 S(int);
69 };
70 const S a(0);
71 const S b = 0;
72 }
73}
Richard Smith7c2bcc92016-09-07 02:14:33 +000074
75struct A {};
76struct B : A {
77 B();
78 B(B&);
79 B(A);
80 B(int);
81};
82B b = 0; // ok, calls B(int) then A(const A&) then B(A).