| 1 |
/* Test C23 unsequenced attribute: invalid contexts. */ |
| 2 |
/* { dg-do compile } */ |
| 3 |
/* { dg-options "-std=c23 -pedantic-errors" } */ |
| 4 |
|
| 5 |
/* This attribute is not valid in most cases on types other than |
| 6 |
type specifiers with function type or function declarators. */ |
| 7 |
|
| 8 |
[[unsequenced]]; /* { dg-error "ignored" } */ |
| 9 |
|
| 10 |
int [[unsequenced]] var; /* { dg-error "ignored" } */ |
| 11 |
|
| 12 |
int array_with_dep_type[2] [[unsequenced]]; /* { dg-error "ignored" } */ |
| 13 |
|
| 14 |
[[unsequenced]] int fn1 (); /* { dg-error "standard 'unsequenced' attribute can only be applied to function declarators or type specifiers with function type" } */ |
| 15 |
|
| 16 |
[[unsequenced]] int fn2 (), fn3 (); /* { dg-error "standard 'unsequenced' attribute can only be applied to function declarators or type specifiers with function type" } */ |
| 17 |
|
| 18 |
int var2 [[unsequenced]]; /* { dg-warning "'unsequenced' attribute only applies to function types" } */ |
| 19 |
|
| 20 |
int fn4 [[unsequenced]] (); /* { dg-error "standard 'unsequenced' attribute can only be applied to function declarators or type specifiers with function type" } */ |
| 21 |
|
| 22 |
int [[unsequenced]] fn5 (); /* { dg-error "ignored" } */ |
| 23 |
|
| 24 |
int z = sizeof (int [[__unsequenced__]]); /* { dg-error "ignored" } */ |
| 25 |
|
| 26 |
/* This is valid, but not really useful, as it can't return results |
| 27 |
in return type nor has any pointer arguments to store results into. */ |
| 28 |
void |
| 29 |
fn6 (int x, double y) [[unsequenced]] |
| 30 |
{ /* { dg-warning "unsequenced' attribute on function type without pointer arguments returning 'void'" } */ |
| 31 |
y = x; |
| 32 |
(void) y; |
| 33 |
} |
| 34 |
|
| 35 |
void |
| 36 |
f (void) |
| 37 |
{ |
| 38 |
int a; |
| 39 |
[[unsequenced]]; /* { dg-error "ignored" } */ |
| 40 |
[[unsequenced]] a = 1; /* { dg-error "ignored" } */ |
| 41 |
[[unsequenced]] label: ; /* { dg-warning "'unsequenced' attribute only applies to function types" } */ |
| 42 |
switch (var) |
| 43 |
{ |
| 44 |
[[unsequenced]] case 1: ; /* { dg-warning "'unsequenced' attribute only applies to function types" } */ |
| 45 |
[[unsequenced]] default: ; /* { dg-warning "'unsequenced' attribute only applies to function types" } */ |
| 46 |
} |
| 47 |
} |