| 1 |
/* Verify that defining a type in __builtin_has_attribute triggers |
| 2 |
the expected -Wc++-compat warning and evaluates as expected. |
| 3 |
Also verify that the expression in __builtin_has_attribute is |
| 4 |
not evaluated. |
| 5 |
|
| 6 |
{ dg-do compile } |
| 7 |
{ dg-options "-O2 -Wall -Wc++-compat -fdump-tree-optimized -ftrack-macro-expansion=0" } */ |
| 8 |
|
| 9 |
#define ATTR(list) __attribute__ (list) |
| 10 |
|
| 11 |
#define A(expect, sym, attr) \ |
| 12 |
typedef int Assert [1 - 2 * !(__builtin_has_attribute (sym, attr) == expect)] |
| 13 |
|
| 14 |
#define assert(expr) \ |
| 15 |
((expr) \ |
| 16 |
? (void)0 \ |
| 17 |
: (__builtin_printf ("Assertion failed on line %i: %s\n", \ |
| 18 |
__LINE__, #expr), \ |
| 19 |
++nfails)) |
| 20 |
|
| 21 |
A (0, struct A { int i; }, aligned); /* { dg-warning "expression is invalid in C\\\+\\\+" } */ |
| 22 |
A (1, struct ATTR ((aligned)) B { int i; }, aligned); /* { dg-warning "expression is invalid in C\\\+\\\+" } */ |
| 23 |
|
| 24 |
|
| 25 |
static int f (void) |
| 26 |
{ |
| 27 |
__builtin_abort (); |
| 28 |
} |
| 29 |
|
| 30 |
int main (void) |
| 31 |
{ |
| 32 |
int n = 0, nfails = 0; |
| 33 |
|
| 34 |
assert (0 == __builtin_has_attribute (int[n++], aligned)); |
| 35 |
assert (1 == __builtin_has_attribute (ATTR ((aligned)) int[n++], aligned)); |
| 36 |
assert (1 == __builtin_has_attribute (ATTR ((aligned)) int[f ()], aligned)); |
| 37 |
assert (1 == 1); |
| 38 |
|
| 39 |
if (n) |
| 40 |
__builtin_abort (); |
| 41 |
|
| 42 |
if (nfails) |
| 43 |
__builtin_abort (); |
| 44 |
|
| 45 |
return 0; |
| 46 |
} |
| 47 |
|
| 48 |
/* { dg-final { scan-tree-dump-times "abort" 0 "optimized" } } */ |