OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.5.1/] [gcc/] [testsuite/] [gcc.dg/] [gnu99-const-expr-3.c] - Blame information for rev 404

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 298 jeremybenn
/* Test for constant expressions: cases involving VLAs and typeof.  */
2
/* Origin: Joseph Myers <joseph@codesourcery.com> */
3
/* { dg-do compile } */
4
/* { dg-options "-std=gnu99 -pedantic-errors" } */
5
 
6
/* It appears address constants may contain casts to variably modified
7
   types.  Whether they should be permitted was discussed in
8
   <http://groups.google.com/group/comp.std.c/msg/923eee5ab690fd98>
9
   <LV7g2Vy3ARF$Ew9Q@romana.davros.org>; since static pointers to VLAs
10
   are definitely permitted within functions and may be initialized
11
   and such initialization involves implicit conversion to a variably
12
   modified type, allowing explicit casts seems appropriate.  Thus,
13
   GCC allows them as long as the "evaluated" size expressions do not
14
   contain the various operators not permitted to be evaluated in a
15
   constant expression, and as long as the result is genuinely
16
   constant (meaning that pointer arithmetic using the size of the VLA
17
   is generally not permitted).  */
18
 
19
static int sa[100];
20
 
21
int
22
f (int m, int n)
23
{
24
  static int (*a1)[n] = &sa;
25
  static int (*a2)[n] = (__typeof__(int (*)[n]))sa;
26
  static int (*a3)[n] = (__typeof__(int (*)[(int){m++}]))sa; /* { dg-error "constant" } */
27
  static int (*a4)[n] = (__typeof__((int (*)[n])sa))sa;
28
  static int (*a5)[n] = (__typeof__((int (*)[m++])sa))sa; /* { dg-error "constant" } */
29
  static int (*a6)[n] = (__typeof__((int (*)[100])(int (*)[m++])sa))sa;
30
  static int (*a7)[n] = (__typeof__((int (*)[n])sa + m++))sa; /* { dg-error "constant" } */
31
  return n;
32
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.