1 extern void *malloc(unsigned long);
3 static inline __attribute__((__const__
)) unsigned squarec(unsigned n
)
8 static inline unsigned square(unsigned n
)
13 static inline unsigned long long bignum(void)
15 return 1000000000000ULL;
18 static inline __attribute__((__const__
)) unsigned long long bignumc(void)
20 return 1000000000000ULL;
23 // test if x is an integer constant expression [C99,C11 6.6p6]
25 (__builtin_types_compatible_p(typeof(0?((void*)((long)(x)*0l)):(int*)1),int*))
27 #define CHX_P(X) __builtin_choose_expr(ICE_P(X), 1, 0)
28 #define CST_P(X) __builtin_constant_p(ICE_P(X))
30 #define TEST(R, X) _Static_assert(ICE_P(X) == R, "ICE_P(" #X ") => " #R); \
31 _Static_assert(ICE_P(ICE_P(X)), "ICE_P2(" #X ")"); \
32 _Static_assert(CHX_P(X) == R, "CHX_P(" #X ") => " #R); \
33 _Static_assert(CST_P(X) == 1, "CST_P(" #X ")")
35 int main(int argc
, char *argv
[])
47 TEST(1, sizeof(long));
53 TEST(0, square(argc
));
55 TEST(0, squarec(argc
));
57 TEST(0, 1+argc
+argc
+1-argc
-argc
);
58 TEST(0, bignum() - 1);
67 TEST(0, v
= malloc(8));
72 TEST(0, ({x
++; 0; }));
73 TEST(0, ({square(y
--); 0; }));
74 TEST(0, (square(x
), 3));
75 TEST(0, (squarec(x
), 3));
76 TEST(0, ({squarec(x
); 3;}));
77 TEST(0, ({squarec(x
);}));
83 * check-name: integer-const-expr
84 * check-command: sparse -Wno-vla $file