annotate gcc/testsuite/gcc.dg/c99-const-expr-11.c @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 04ced10e8804
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* Test for constant expressions: cases involving VLAs. */
kono
parents:
diff changeset
2 /* Origin: Joseph Myers <joseph@codesourcery.com> */
kono
parents:
diff changeset
3 /* { dg-do compile } */
kono
parents:
diff changeset
4 /* { dg-options "-std=iso9899:1999 -pedantic-errors" } */
kono
parents:
diff changeset
5
kono
parents:
diff changeset
6 /* It appears address constants may contain casts to variably modified
kono
parents:
diff changeset
7 types. Whether they should be permitted was discussed in
kono
parents:
diff changeset
8 <http://groups.google.com/group/comp.std.c/msg/923eee5ab690fd98>
kono
parents:
diff changeset
9 <LV7g2Vy3ARF$Ew9Q@romana.davros.org>; since static pointers to VLAs
kono
parents:
diff changeset
10 are definitely permitted within functions and may be initialized
kono
parents:
diff changeset
11 and such initialization involves implicit conversion to a variably
kono
parents:
diff changeset
12 modified type, allowing explicit casts seems appropriate. Thus,
kono
parents:
diff changeset
13 GCC allows them as long as the "evaluated" size expressions do not
kono
parents:
diff changeset
14 contain the various operators not permitted to be evaluated in a
kono
parents:
diff changeset
15 constant expression, and as long as the result is genuinely
kono
parents:
diff changeset
16 constant (meaning that pointer arithmetic using the size of the VLA
kono
parents:
diff changeset
17 is generally not permitted). */
kono
parents:
diff changeset
18
kono
parents:
diff changeset
19 static int sa[100];
kono
parents:
diff changeset
20
kono
parents:
diff changeset
21 volatile int nv;
kono
parents:
diff changeset
22
kono
parents:
diff changeset
23 int
kono
parents:
diff changeset
24 f (int m, int n)
kono
parents:
diff changeset
25 {
kono
parents:
diff changeset
26 static int (*a1)[n] = &sa;
kono
parents:
diff changeset
27 static int (*a2)[n] = (int (*)[n])sa;
kono
parents:
diff changeset
28 static int (*a3)[n] = (int (*)[(int){n}])sa;
kono
parents:
diff changeset
29 static int (*a4)[n] = (int (*)[(int){m++}])sa; /* { dg-error "constant" } */
kono
parents:
diff changeset
30 static int (*a5)[n] = (int (*)[(int){++m}])sa; /* { dg-error "constant" } */
kono
parents:
diff changeset
31 static int (*a6)[n] = (int (*)[(int){m--}])sa; /* { dg-error "constant" } */
kono
parents:
diff changeset
32 static int (*a7)[n] = (int (*)[(int){--m}])sa; /* { dg-error "constant" } */
kono
parents:
diff changeset
33 static int (*a8)[n] = (int (*)[(m=n)])sa; /* { dg-error "constant" } */
kono
parents:
diff changeset
34 static int (*a9)[n] = (int (*)[(m+=n)])sa; /* { dg-error "constant" } */
kono
parents:
diff changeset
35 static int (*a10)[n] = (int (*)[f(m,n)])sa; /* { dg-error "constant" } */
kono
parents:
diff changeset
36 static int (*a11)[n] = (int (*)[(m,n)])sa; /* { dg-error "constant" } */
kono
parents:
diff changeset
37 static int (*a12)[n] = (int (*)[sizeof(int[n])])sa;
kono
parents:
diff changeset
38 static int (*a13)[n] = (int (*)[sizeof(int[m++])])sa; /* { dg-error "constant" } */
kono
parents:
diff changeset
39 static int (*a14)[n] = (int (*)[sizeof(*a1)])sa;
kono
parents:
diff changeset
40 static int (*a15)[n] = (int (*)[sizeof(*(int (*)[n])sa)])sa;
kono
parents:
diff changeset
41 static int (*a16)[n] = (int (*)[sizeof(*(int (*)[m++])sa)])sa; /* { dg-error "constant" } */
kono
parents:
diff changeset
42 static int (*a17)[n] = (int (*)[nv])sa;
kono
parents:
diff changeset
43 typedef int (*vmt)[m++];
kono
parents:
diff changeset
44 static int (*a18)[n] = (vmt)sa;
kono
parents:
diff changeset
45 return n;
kono
parents:
diff changeset
46 }