brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.9 KiB · 5f450f2 Raw
58 lines · cpp
1// RUN: %clang_cc1 %s -fblocks -fsyntax-only -Wcast-function-type -Wno-cast-function-type-strict -verify2// RUN: %clang_cc1 %s -fblocks -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,...);13typedef int (&f8)(long, int);14 15f1 *a;16f2 *b;17f3 *c;18f4 *d;19f5 *e;20f6 *f;21f7 *g;22 23struct S24{25  void foo (int*);26  void bar (int);27};28 29typedef void (S::*mf)(int);30 31enum E : long;32int efunc(E);33 34// Produce the underlying `long` type implicitly.35enum E2 { big = __LONG_MAX__ };36int e2func(E2);37 38void foo() {39  a = (f1 *)x;40  a = (f1 *)efunc; // enum is just type system sugar, still passed as a long.41  a = (f1 *)e2func; // enum is just type system sugar, still passed as a long.42  b = (f2 *)x; // expected-warning {{cast from 'int (*)(long)' to 'f2 *' (aka 'int (*)(void *)') converts to incompatible function type}}43  b = reinterpret_cast<f2 *>(x); // expected-warning {{cast from 'int (*)(long)' to 'f2 *' (aka 'int (*)(void *)') converts to incompatible function type}}44  c = (f3 *)x;45  d = (f4 *)x; // expected-warning {{cast from 'int (*)(long)' to 'f4 *' (aka 'void (*)(...)') converts to incompatible function type}}46  e = (f5 *)x;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;49 50  mf p1 = (mf)&S::foo; // expected-warning {{cast from 'void (S::*)(int *)' to 'mf' (aka 'void (S::*)(int)') converts to incompatible function type}}51 52  f8 f2 = (f8)x; // expected-warning {{cast from 'int (long)' to 'f8' (aka 'int (&)(long, int)') converts to incompatible function type}}53  (void)f2;54 55  int (^y)(long);56  f = (f6 *)y; // expected-warning {{cast from 'int (^)(long)' to 'f6 *' (aka 'int (*)(long, int)') converts to incompatible function type}}57}58