40 lines · c
1// RUN: %clang_cc1 %s -fsyntax-only -Wcast-function-type -Wno-cast-function-type-strict -verify2// RUN: %clang_cc1 %s -fsyntax-only -Wextra -Wno-cast-function-type-strict -verify3 4int x(long);5 6typedef int (f1)(long);7typedef int (f2)(void*);8typedef int (f3)();9typedef void (f4)();10typedef void (f5)(void);11typedef int (f6)(long, int);12typedef int (f7)(long,...);13 14f1 *a;15f2 *b;16f3 *c;17f4 *d;18f5 *e;19f6 *f;20f7 *g;21 22enum E : long;23int efunc(enum E);24 25// Produce the underlying `long` type implicitly.26enum E2 { big = __LONG_MAX__ };27int e2func(enum E2);28 29void 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