| 1 |
/* Test for constant expressions: __builtin_choose_expr. */ |
| 2 |
/* Origin: Joseph Myers <[email protected]> */ |
| 3 |
/* { dg-do compile } */ |
| 4 |
/* { dg-options "-std=gnu99 -pedantic-errors" } */ |
| 5 |
|
| 6 |
#include <limits.h> |
| 7 |
|
| 8 |
int a, b, c; |
| 9 |
|
| 10 |
void |
| 11 |
f (void) |
| 12 |
{ |
| 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) |
| 17 |
}; |
| 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 *-*-* } .-1 } */ |
| 23 |
a = __builtin_choose_expr (1 / 0, 0, 0); /* { dg-warning "division by zero" } */ |
| 24 |
/* { dg-error "not a constant" "error" { target *-*-* } .-1 } */ |
| 25 |
a = __builtin_choose_expr ((1 ? 1 : a), b, c); /* { dg-error "constant" } */ |
| 26 |
} |