gcc_typeof.c revision 1.1
1/*	$NetBSD: gcc_typeof.c,v 1.1 2021/07/25 10:57:38 rillig Exp $	*/
2# 3 "gcc_typeof.c"
3
4/*
5 * Tests for the GCC extension 'typeof'.
6 *
7 * https://gcc.gnu.org/onlinedocs/gcc/Typeof.html
8 */
9
10void take_double(typeof(0.0));
11
12void take_function_double_returning_double(
13    typeof(0.0)(
14	/* FIXME: GCC can parse this */
15	/* expect+1: error: syntax error 'typeof' [249] */
16	typeof(0.0)
17    )
18);
19
20void
21cast(double(*fn)(double))
22{
23	take_double(0.0);
24
25	/* expect+1: warning: passing 'pointer to function(double) returning double' to incompatible 'double', arg #1 [155] */
26	take_double(fn);
27
28	/* XXX: oops; GCC detects this type mismatch. probably due to the parse error. */
29	take_function_double_returning_double(0.0);
30
31	take_function_double_returning_double(fn);
32
33	/* identity cast */
34	take_function_double_returning_double((double (*)(double))fn);
35}
36