Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / SemaCXX / warn-cast-function-type.cpp
blobc613aaea1e33f266474fa85f35104c548faf54b8
1 // RUN: %clang_cc1 %s -fblocks -fsyntax-only -Wcast-function-type -Wno-cast-function-type-strict -verify
3 int x(long);
5 typedef int (f1)(long);
6 typedef int (f2)(void*);
7 typedef int (f3)(...);
8 typedef void (f4)(...);
9 typedef void (f5)(void);
10 typedef int (f6)(long, int);
11 typedef int (f7)(long,...);
12 typedef int (&f8)(long, int);
14 f1 *a;
15 f2 *b;
16 f3 *c;
17 f4 *d;
18 f5 *e;
19 f6 *f;
20 f7 *g;
22 struct S
24 void foo (int*);
25 void bar (int);
28 typedef void (S::*mf)(int);
30 void foo() {
31 a = (f1 *)x;
32 b = (f2 *)x; // expected-warning {{cast from 'int (*)(long)' to 'f2 *' (aka 'int (*)(void *)') converts to incompatible function type}}
33 b = reinterpret_cast<f2 *>(x); // expected-warning {{cast from 'int (*)(long)' to 'f2 *' (aka 'int (*)(void *)') converts to incompatible function type}}
34 c = (f3 *)x;
35 d = (f4 *)x; // expected-warning {{cast from 'int (*)(long)' to 'f4 *' (aka 'void (*)(...)') converts to incompatible function type}}
36 e = (f5 *)x;
37 f = (f6 *)x; // expected-warning {{cast from 'int (*)(long)' to 'f6 *' (aka 'int (*)(long, int)') converts to incompatible function type}}
38 g = (f7 *)x;
40 mf p1 = (mf)&S::foo; // expected-warning {{cast from 'void (S::*)(int *)' to 'mf' (aka 'void (S::*)(int)') converts to incompatible function type}}
42 f8 f2 = (f8)x; // expected-warning {{cast from 'int (long)' to 'f8' (aka 'int (&)(long, int)') converts to incompatible function type}}
43 (void)f2;
45 int (^y)(long);
46 f = (f6 *)y; // expected-warning {{cast from 'int (^)(long)' to 'f6 *' (aka 'int (*)(long, int)') converts to incompatible function type}}