Debian Codegraph @

gcc/testsuite/gcc.dg/c23-attr-reproducible-2.c

raw
1 /* Test C23 reproducible 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 [[reproducible]]; /* { dg-error "ignored" } */
9
10 int [[reproducible]] var; /* { dg-error "ignored" } */
11
12 int array_with_dep_type[2] [[reproducible]]; /* { dg-error "ignored" } */
13
14 [[reproducible]] int fn1 (); /* { dg-error "standard 'reproducible' attribute can only be applied to function declarators or type specifiers with function type" } */
15
16 [[reproducible]] int fn2 (), fn3 (); /* { dg-error "standard 'reproducible' attribute can only be applied to function declarators or type specifiers with function type" } */
17
18 int var2 [[reproducible]]; /* { dg-warning "'reproducible' attribute only applies to function types" } */
19
20 int fn4 [[reproducible]] (); /* { dg-error "standard 'reproducible' attribute can only be applied to function declarators or type specifiers with function type" } */
21
22 int [[reproducible]] fn5 (); /* { dg-error "ignored" } */
23
24 int z = sizeof (int [[__reproducible__]]); /* { 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) [[reproducible]]
30 { /* { dg-warning "reproducible' 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 [[reproducible]]; /* { dg-error "ignored" } */
40 [[reproducible]] a = 1; /* { dg-error "ignored" } */
41 [[reproducible]] label: ; /* { dg-warning "'reproducible' attribute only applies to function types" } */
42 switch (var)
43 {
44 [[reproducible]] case 1: ; /* { dg-warning "'reproducible' attribute only applies to function types" } */
45 [[reproducible]] default: ; /* { dg-warning "'reproducible' attribute only applies to function types" } */
46 }
47 }