gcc_typeof.c revision 1.2
1/* $NetBSD: gcc_typeof.c,v 1.2 2021/07/25 11:19:51 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 /* 14 * FIXME: lint's grammar uses 'typeof cast_expression', while GCC's 15 * c_parser_typeof_specifier uses 'typeof ( expression )'. The crucial 16 * difference is that lint parses the following expression as 'typeof 17 * ((0.0)(typeof(0.0))', that is, it tries to call the function 0.0, 18 * which of course is nonsense. 19 */ 20 typeof(0.0)( 21 /* FIXME: GCC can parse this */ 22 /* expect+1: error: syntax error 'typeof' [249] */ 23 typeof(0.0) 24 ) 25); 26 27void 28cast(double(*fn)(double)) 29{ 30 take_double(0.0); 31 32 /* expect+1: warning: passing 'pointer to function(double) returning double' to incompatible 'double', arg #1 [155] */ 33 take_double(fn); 34 35 /* XXX: oops; GCC detects this type mismatch. probably due to the parse error. */ 36 take_function_double_returning_double(0.0); 37 38 take_function_double_returning_double(fn); 39 40 /* identity cast */ 41 take_function_double_returning_double((double (*)(double))fn); 42} 43