aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/c23-attr-unsequenced-2.c
blob: 85cc150f1ebcdc6d2c1a1167c03f57e3a27c62b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/* Test C23 unsequenced attribute: invalid contexts.  */
/* { dg-do compile } */
/* { dg-options "-std=c23 -pedantic-errors" } */

/* This attribute is not valid in most cases on types other than
   type specifiers with function type or function declarators.  */

[[unsequenced]]; /* { dg-error "ignored" } */

int [[unsequenced]] var; /* { dg-error "ignored" } */

int array_with_dep_type[2] [[unsequenced]]; /* { dg-error "ignored" } */

[[unsequenced]] int fn1 (); /* { dg-error "standard 'unsequenced' attribute can only be applied to function declarators or type specifiers with function type" } */

[[unsequenced]] int fn2 (), fn3 (); /* { dg-error "standard 'unsequenced' attribute can only be applied to function declarators or type specifiers with function type" } */

int var2 [[unsequenced]]; /* { dg-warning "'unsequenced' attribute only applies to function types" } */

int fn4 [[unsequenced]] (); /* { dg-error "standard 'unsequenced' attribute can only be applied to function declarators or type specifiers with function type" } */

int [[unsequenced]] fn5 (); /* { dg-error "ignored" } */

int z = sizeof (int [[__unsequenced__]]); /* { dg-error "ignored" } */

/* This is valid, but not really useful, as it can't return results
   in return type nor has any pointer arguments to store results into.  */
void
fn6 (int x, double y) [[unsequenced]]
{ /* { dg-warning "unsequenced' attribute on function type without pointer arguments returning 'void'" } */
  y = x;
  (void) y;
}

void
f (void)
{
  int a;
  [[unsequenced]]; /* { dg-error "ignored" } */
  [[unsequenced]] a = 1; /* { dg-error "ignored" } */
  [[unsequenced]] label: ; /* { dg-warning "'unsequenced' attribute only applies to function types" } */
  switch (var)
    {
    [[unsequenced]] case 1: ; /* { dg-warning "'unsequenced' attribute only applies to function types" } */
    [[unsequenced]] default: ; /* { dg-warning "'unsequenced' attribute only applies to function types" } */
    }
}