blob: 76b09997ef1e4c86a86b94f48b4bfbea664fd4f1 [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'}}
19 static_cast<B>(10); // expected-error {{no matching conversion for static_cast from 'int' to 'B'}} \\
Argyrios Kyrtzidis40cec832010-09-19 23:03:35 +000020 // expected-warning {{expression result unused}}
Fariborz Jahanianb3c44f92009-10-01 20:39:51 +000021}
22
Douglas Gregorad8b2222009-11-06 01:14:41 +000023template<class T>
24struct X0 {
25 X0(const T &);
26};
27
28template<class T>
29X0<T> make_X0(const T &Val) {
30 return X0<T>(Val);
31}
32
33void test_X0() {
Douglas Gregore6565622010-02-09 07:26:29 +000034 const char array[2] = { 'a', 'b' };
Douglas Gregorad8b2222009-11-06 01:14:41 +000035 make_X0(array);
36}
Douglas Gregorf4f2ff72009-11-06 05:48:00 +000037
38// PR5210 recovery
39class C {
40protected:
41 template <int> float* &f0(); // expected-note{{candidate}}
42 template <unsigned> float* &f0(); // expected-note{{candidate}}
43
44 void f1() {
45 static_cast<float*>(f0<0>()); // expected-error{{ambiguous}}
46 }
47};
David Blaikie282ad872012-10-16 18:53:14 +000048
49void *intToPointer1(short s) {
50 return (void*)s; // expected-warning{{cast to 'void *' from smaller integer type 'short'}}
51}
52
53void *intToPointer2(short s) {
54 return reinterpret_cast<void*>(s);
55}
56
57void *intToPointer3(bool b) {
58 return (void*)b;
59}
60
61void *intToPointer4() {
62 return (void*)(3 + 7);
63}
64
65void *intToPointer5(long l) {
66 return (void*)l;
67}
Eli Friedman61a511f2013-06-20 01:35:13 +000068
69struct AmbiguousCast {
70 operator int(); // expected-note {{candidate function}}
71 operator unsigned int(); // expected-note {{candidate function}}
72};
73long long AmbiguousCastFunc(AmbiguousCast& a) {
74 return static_cast<long long>(a); // expected-error {{ambiguous conversion for static_cast from 'AmbiguousCast' to 'long long'}}
75}