1*17051365SRichard Smith // RUN: %clang_cc1 -x c++ %s -fblocks -fsyntax-only -Wcast-function-type -triple x86_64-- -verify
2*17051365SRichard Smith 
3*17051365SRichard Smith int x(long);
4*17051365SRichard Smith 
5*17051365SRichard Smith typedef int (f1)(long);
6*17051365SRichard Smith typedef int (f2)(void*);
7*17051365SRichard Smith typedef int (f3)(...);
8*17051365SRichard Smith typedef void (f4)(...);
9*17051365SRichard Smith typedef void (f5)(void);
10*17051365SRichard Smith typedef int (f6)(long, int);
11*17051365SRichard Smith typedef int (f7)(long,...);
12*17051365SRichard Smith typedef int (&f8)(long, int);
13*17051365SRichard Smith 
14*17051365SRichard Smith f1 *a;
15*17051365SRichard Smith f2 *b;
16*17051365SRichard Smith f3 *c;
17*17051365SRichard Smith f4 *d;
18*17051365SRichard Smith f5 *e;
19*17051365SRichard Smith f6 *f;
20*17051365SRichard Smith f7 *g;
21*17051365SRichard Smith 
22*17051365SRichard Smith struct S
23*17051365SRichard Smith {
24*17051365SRichard Smith   void foo (int*);
25*17051365SRichard Smith   void bar (int);
26*17051365SRichard Smith };
27*17051365SRichard Smith 
28*17051365SRichard Smith typedef void (S::*mf)(int);
29*17051365SRichard Smith 
foo()30*17051365SRichard Smith void foo() {
31*17051365SRichard Smith   a = (f1 *)x;
32*17051365SRichard Smith   b = (f2 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f2 *' (aka 'int (*)(void *)') converts to incompatible function type}} */
33*17051365SRichard Smith   b = reinterpret_cast<f2 *>(x); /* expected-warning {{cast from 'int (*)(long)' to 'f2 *' (aka 'int (*)(void *)') converts to incompatible function type}} */
34*17051365SRichard Smith   c = (f3 *)x;
35*17051365SRichard Smith   d = (f4 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f4 *' (aka 'void (*)(...)') converts to incompatible function type}} */
36*17051365SRichard Smith   e = (f5 *)x;
37*17051365SRichard Smith   f = (f6 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f6 *' (aka 'int (*)(long, int)') converts to incompatible function type}} */
38*17051365SRichard Smith   g = (f7 *)x;
39*17051365SRichard Smith 
40*17051365SRichard Smith   mf p1 = (mf)&S::foo; /* expected-warning {{cast from 'void (S::*)(int *)' to 'mf' (aka 'void (S::*)(int)') converts to incompatible function type}} */
41*17051365SRichard Smith 
42*17051365SRichard Smith   f8 f2 = (f8)x; /* expected-warning {{cast from 'int (long)' to 'f8' (aka 'int (&)(long, int)') converts to incompatible function type}} */
43*17051365SRichard Smith   (void)f2;
44*17051365SRichard Smith 
45*17051365SRichard Smith   int (^y)(long);
46*17051365SRichard Smith   f = (f6 *)y; /* expected-warning {{cast from 'int (^)(long)' to 'f6 *' (aka 'int (*)(long, int)') converts to incompatible function type}} */
47*17051365SRichard Smith }
48