summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/c2x-attr-syntax-3.c
blob: 1f883d825e026769c80bc554f27515b29de3f4aa (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
48
49
50
51
52
53
54
55
56
/* Test C2x attribute syntax.  Invalid uses of attributes.  */
/* { dg-do compile } */
/* { dg-options "-std=c2x -pedantic-errors" } */

/* Prefix attributes not allowed on declarations without declarators.  */

[[]] struct s { int a; }; /* { dg-error "empty declaration" } */

[[]] union u { int a; }; /* { dg-error "empty declaration" } */

void
f1 (void)
{
  [[]] struct t { int a; }; /* { dg-error "empty declaration" } */
}

/* Prefix attributes not allowed on _Static_assert.  */

[[]] _Static_assert (1); /* { dg-error "expected" } */

void
f2 (void)
{
  [[]] _Static_assert (1); /* { dg-error "expected" } */
}

/* Declarations, including attribute declarations, cannot appear after
   labels.  */

void
f3 (void)
{
 x: [[]];; /* { dg-error "can only be part of a statement" } */
}

/* Prefix attributes cannot appear on type names.  */

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

/* Attributes are not allowed after struct, union or enum, except when
   the type contents are being defined or the declaration is just
   "struct-or-union atribute-specifier-sequence identifier;".  */

const struct [[]] s2; /* { dg-warning "useless type qualifier" } */
/* { dg-error "invalid use of attributes in empty declaration" "invalid" { target *-*-* } .-1 } */

const union [[]] u2; /* { dg-warning "useless type qualifier" } */
/* { dg-error "invalid use of attributes in empty declaration" "invalid" { target *-*-* } .-1 } */

struct [[]] s3 *sv; /* { dg-error "expected" } */

union [[]] u3 *uv; /* { dg-error "expected" } */

enum e { E1 };

enum [[]] e *ev; /* { dg-error "expected" } */