xref: /llvm-project/clang/test/Sema/warn-cast-function-type.c (revision 2bc098b8aba089fe8328b3b8a8b6b6816cd5a908)
1 // RUN: %clang_cc1 %s -fsyntax-only -Wcast-function-type -Wno-cast-function-type-strict -verify
2 // RUN: %clang_cc1 %s -fsyntax-only -Wextra -Wno-cast-function-type-strict -verify
3 
4 int x(long);
5 
6 typedef int (f1)(long);
7 typedef int (f2)(void*);
8 typedef int (f3)();
9 typedef void (f4)();
10 typedef void (f5)(void);
11 typedef int (f6)(long, int);
12 typedef int (f7)(long,...);
13 
14 f1 *a;
15 f2 *b;
16 f3 *c;
17 f4 *d;
18 f5 *e;
19 f6 *f;
20 f7 *g;
21 
22 enum E : long;
23 int efunc(enum E);
24 
25 // Produce the underlying `long` type implicitly.
26 enum E2 { big = __LONG_MAX__ };
27 int e2func(enum E2);
28 
foo(void)29 void foo(void) {
30   a = (f1 *)x;
31   a = (f1 *)efunc; // enum is just type system sugar, still passed as a long.
32   a = (f1 *)e2func; // enum is just type system sugar, still passed as a long.
33   b = (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;
39 }
40