2014-07-29 Ed Smith-Rowland <3dw4rd@verizon.net>
[official-gcc.git] / gcc / testsuite / gcc.dg / gnu99-const-expr-2.c
blobf9acef81a949063c9935ce3d880afb18658cf2dd
1 /* Test for constant expressions: __builtin_choose_expr. */
2 /* Origin: Joseph Myers <joseph@codesourcery.com> */
3 /* { dg-do compile } */
4 /* { dg-options "-std=gnu99 -pedantic-errors" } */
6 #include <limits.h>
8 int a, b, c;
10 void
11 f (void)
13 /* __builtin_choose_expr acts exactly like the chosen argument for
14 all constant expression purposes. */
15 enum e {
16 E1 = __builtin_choose_expr (1, 1, ++b)
18 /* The first argument to __builtin_choose_expr must be an integer
19 constant expression. */
20 a = __builtin_choose_expr ((void *)0, b, c); /* { dg-error "constant" } */
21 a = __builtin_choose_expr (0 * (INT_MAX + 1), b, c); /* { dg-warning "integer overflow in expression" } */
22 /* { dg-error "overflow in constant expression" "constant" { target *-*-* } 21 } */
23 a = __builtin_choose_expr (1 / 0, 0, 0); /* { dg-warning "division by zero" } */
24 /* { dg-error "not a constant" "error" { target *-*-* } 23 } */
25 a = __builtin_choose_expr ((1 ? 1 : a), b, c); /* { dg-error "constant" } */