xref: /llvm-project/clang/test/Sema/warn-cast-function-type-strict.c (revision 2bc098b8aba089fe8328b3b8a8b6b6816cd5a908)
1 // RUN: %clang_cc1 %s -fsyntax-only -Wcast-function-type -verify=expected,strict
2 // RUN: %clang_cc1 %s -fsyntax-only -Wcast-function-type-strict -verify=expected,strict
3 // RUN: %clang_cc1 %s -fsyntax-only -Wextra -Wno-ignored-qualifiers -verify
4 
5 int t(int array[static 12]);
6 int u(int i);
7 const int v(int i);
8 int x(long);
9 
10 typedef int (f1)(long);
11 typedef int (f2)(void*);
12 typedef int (f3)();
13 typedef void (f4)();
14 typedef void (f5)(void);
15 typedef int (f6)(long, int);
16 typedef int (f7)(long,...);
17 typedef int (f8)(int *);
18 typedef int (f9)(const int);
19 typedef int (f10)(int);
20 
21 f1 *a;
22 f2 *b;
23 f3 *c;
24 f4 *d;
25 f5 *e;
26 f6 *f;
27 f7 *g;
28 f8 *h;
29 f9 *i;
30 f10 *j;
31 
32 enum E : long;
33 int efunc(enum E);
34 
35 // Produce the underlying `long` type implicitly.
36 enum E2 { big = __LONG_MAX__ };
37 int e2func(enum E2);
38 
foo(void)39 void foo(void) {
40   a = (f1 *)x;
41   a = (f1 *)efunc; // strict-warning {{cast from 'int (*)(enum E)' to 'f1 *' (aka 'int (*)(long)') converts to incompatible function type}}
42   a = (f1 *)e2func; // strict-warning {{cast from 'int (*)(enum E2)' to 'f1 *' (aka 'int (*)(long)') converts to incompatible function type}}
43   b = (f2 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f2 *' (aka 'int (*)(void *)') converts to incompatible function type}} */
44   c = (f3 *)x; /* strict-warning {{cast from 'int (*)(long)' to 'f3 *' (aka 'int (*)()') converts to incompatible function type}} */
45   d = (f4 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f4 *' (aka 'void (*)()') converts to incompatible function type}} */
46   e = (f5 *)x; /* strict-warning {{cast from 'int (*)(long)' to 'f5 *' (aka 'void (*)(void)') converts to incompatible function type}} */
47   f = (f6 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f6 *' (aka 'int (*)(long, int)') converts to incompatible function type}} */
48   g = (f7 *)x; /* strict-warning {{cast from 'int (*)(long)' to 'f7 *' (aka 'int (*)(long, ...)') converts to incompatible function type}} */
49   h = (f8 *)t;
50   i = (f9 *)u;
51   // FIXME: return type qualifier should not be included in the function type . Warning should be absent after this issue is fixed. https://github.com/llvm/llvm-project/issues/39494 .
52   j = (f10 *)v; /* strict-warning {{cast from 'const int (*)(int)' to 'f10 *' (aka 'int (*)(int)') converts to incompatible function type}} */
53 }
54