OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gcc-4.2.2/] [gcc/] [testsuite/] [gcc.dg/] [c99-complit-2.c] - Blame information for rev 816

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 149 jeremybenn
/* Test for compound literals: in C99 only.  Test for invalid uses.  */
2
/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
3
/* { dg-do compile } */
4
/* { dg-options "-std=iso9899:1999 -pedantic-errors" } */
5
 
6
struct s { int a; int b; };
7
union u { int c; int d; };
8
 
9
struct si;
10
union ui;
11
 
12
void
13
foo (int a)
14
{
15
  /* The type name must not be incomplete (apart from arrays of unknown
16
     size), or a function type, or a VLA type.  */
17
  (void) { 1 }; /* { dg-bogus "warning" "warning in place of error" } */
18
  /* { dg-error "init" "void type" { target *-*-* } 17 } */
19
  &(struct si) { 1 }; /* { dg-bogus "warning" "warning in place of error" } */
20
  /* { dg-error "init" "incomplete struct type" { target *-*-* } 19 } */
21
  &(union ui) { 1 }; /* { dg-bogus "warning" "warning in place of error" } */
22
  /* { dg-error "init" "incomplete union type" { target *-*-* } 21 } */
23
  (void (void)) { 0 }; /* { dg-bogus "warning" "warning in place of error" } */
24
  /* { dg-error "init" "function type" { target *-*-* } 23 } */
25
  (int [a]) { 1 }; /* { dg-bogus "warning" "warning in place of error" } */
26
  /* { dg-error "init|variable" "VLA type" { target *-*-* } 25 } */
27
  /* Initializers must not attempt to initialize outside the object
28
     declared.  */
29
  (int [1]) { [1] = 2 }; /* { dg-bogus "warning" "warning in place of error" } */
30
  /* { dg-error "init" "value outside array" { target *-*-* } 29 } */
31
  (int [1]) { [-1] = 2 }; /* { dg-bogus "warning" "warning in place of error" } */
32
  /* { dg-error "init" "value outside array" { target *-*-* } 31 } */
33
  (int [1]) { 0, 1 }; /* { dg-bogus "warning" "warning in place of error" } */
34
  /* { dg-error "init" "value outside array" { target *-*-* } 33 } */
35
}
36
 
37
int z;
38
 
39
/* Outside a function, initializers must be constant.  */
40
struct s *s0 = &(struct s) { 0, z }; /* { dg-bogus "warning" "warning in place of error" } */
41
/* { dg-error "init" "non-const" { target *-*-* } 40 } */
42
int sz = sizeof((struct s) { 0, z }); /* { dg-bogus "warning" "warning in place of error" } */
43
/* { dg-error "init" "non-const" { target *-*-* } 42 } */
44
 
45
/* Compound literals aren't themselves constant expressions.  */
46
int x = (int) { 0 }; /* { dg-bogus "warning" "warning in place of error" } */
47
/* { dg-error "init" "non-const" { target *-*-* } 46 } */
48
 
49
/* Nor are they suitable structure or union initializers
50
   outside a function.  */
51
struct s s1 = (struct s) { 0, 1 }; /* { dg-bogus "warning" "warning in place of error" } */
52
/* { dg-error "init" "struct bad init" { target *-*-* } 51 } */
53
union u u1 = (union u) { 0 }; /* { dg-bogus "warning" "warning in place of error" } */
54
/* { dg-error "init" "union bad init" { target *-*-* } 53 } */
55
 
56
/* They aren't suitable for array initializers, either inside or outside
57
   a function.  */
58
int y[2] = (int [2]) { 0, 1 }; /* { dg-bogus "warning" "warning in place of error" } */
59
/* { dg-error "init" "array bad init" { target *-*-* } 58 } */
60
 
61
void
62
bar (void)
63
{
64
  struct s s2 = (struct s) { 0, 1 };
65
  union u u2 = (union u) { 0 };
66
  int z[2] = (int [2]) { 0, 1 }; /* { dg-bogus "warning" "warning in place of error" } */
67
  /* { dg-error "init" "array bad init" { target *-*-* } 66 } */
68
}

powered by: WebSVN 2.1.0

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