blob: 4d5abfdcfb1e3fca30ef4e5768234e260797308f [file] [log] [blame]
David Blaikie282ad872012-10-16 18:53:14 +00001// RUN: %clang_cc1 -fsyntax-only -triple x86_64-unknown-unknown -verify %s -std=c++11
Fariborz Jahanianb3c44f92009-10-01 20:39:51 +00002
3struct R {
4 R(int);
5};
6
7struct A {
8 A(R);
9};
10
Sebastian Redl22653ba2011-08-30 19:58:05 +000011struct B { // expected-note 3 {{candidate constructor (the implicit copy constructor) not viable}} \
12 expected-note 3 {{candidate constructor (the implicit move constructor) not viable}}
John McCall909acf82011-02-14 18:34:10 +000013 B(A); // expected-note 3 {{candidate constructor not viable}}
Fariborz Jahanianb3c44f92009-10-01 20:39:51 +000014};
15
16int main () {
John McCall909acf82011-02-14 18:34:10 +000017 B(10); // expected-error {{no matching conversion for functional-style cast from 'int' to 'B'}}
18 (B)10; // expected-error {{no matching conversion for C-style cast from 'int' to 'B'}}
Eli Friedman3fd26b82013-07-26 23:47:47 +000019 static_cast<B>(10); // expected-error {{no matching conversion for static_cast from 'int' to 'B'}}
Fariborz Jahanianb3c44f92009-10-01 20:39:51 +000020}
21
Douglas Gregorad8b2222009-11-06 01:14:41 +000022template<class T>
23struct X0 {
24 X0(const T &);
25};
26
27template<class T>
28X0<T> make_X0(const T &Val) {
29 return X0<T>(Val);
30}
31
32void test_X0() {
Douglas Gregore6565622010-02-09 07:26:29 +000033 const char array[2] = { 'a', 'b' };
Douglas Gregorad8b2222009-11-06 01:14:41 +000034 make_X0(array);
35}
Douglas Gregorf4f2ff72009-11-06 05:48:00 +000036
37// PR5210 recovery
38class C {
39protected:
40 template <int> float* &f0(); // expected-note{{candidate}}
41 template <unsigned> float* &f0(); // expected-note{{candidate}}
42
43 void f1() {
44 static_cast<float*>(f0<0>()); // expected-error{{ambiguous}}
45 }
46};
David Blaikie282ad872012-10-16 18:53:14 +000047
48void *intToPointer1(short s) {
49 return (void*)s; // expected-warning{{cast to 'void *' from smaller integer type 'short'}}
50}
51
52void *intToPointer2(short s) {
53 return reinterpret_cast<void*>(s);
54}
55
56void *intToPointer3(bool b) {
57 return (void*)b;
58}
59
60void *intToPointer4() {
61 return (void*)(3 + 7);
62}
63
64void *intToPointer5(long l) {
65 return (void*)l;
66}
Eli Friedman61a511f2013-06-20 01:35:13 +000067
68struct AmbiguousCast {
69 operator int(); // expected-note {{candidate function}}
70 operator unsigned int(); // expected-note {{candidate function}}
71};
72long long AmbiguousCastFunc(AmbiguousCast& a) {
73 return static_cast<long long>(a); // expected-error {{ambiguous conversion for static_cast from 'AmbiguousCast' to 'long long'}}
74}
Eli Friedman3fd26b82013-07-26 23:47:47 +000075
76namespace PR16680 {
77 void f(int (*__pf)());
78 int g() {
79 f(reinterpret_cast<int>(0.0f)); // expected-error {{reinterpret_cast from 'float' to 'int' is not allowed}}
80 }
81}