(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
init-bad-1.c
       1  /* Test diagnostics for various bad initializers.  */
       2  /* Origin: Joseph Myers <joseph@codesourcery.com> */
       3  /* { dg-do compile } */
       4  /* { dg-options "-std=gnu99" } */
       5  
       6  void f(void);
       7  void g(void) = f; /* { dg-error "function 'g' is initialized like a variable" } */
       8  
       9  void h(a)
      10       int a = 1; /* { dg-error "parameter 'a' is initialized" } */
      11  {
      12    struct s x = { 0 }; /* { dg-error "variable 'x' has initializer but incomplete type" } */
      13    /* { dg-warning "excess elements|near init" "excess" { target *-*-* } .-1 } */
      14    /* { dg-error "storage size" "size" { target *-*-* } .-2 } */
      15  }
      16  
      17  char s[1] = "x";
      18  char s1[1] = { "x" };
      19  char t[1] = "xy"; /* { dg-warning "initializer-string for array of 'char' is too long" } */
      20  char t1[1] = { "xy" }; /* { dg-warning "initializer-string for array of 'char' is too long" } */
      21  char u[1] = { "x", "x" }; /* { dg-error "excess elements in 'char' array initializer" } */
      22  /* { dg-message "near init" "near" { target *-*-* } .-1 } */
      23  
      24  int i = { };
      25  
      26  int j = { 1 };
      27  
      28  int k = { 1, 2 }; /* { dg-warning "excess elements in scalar initializer" } */
      29  /* { dg-message "near init" "near" { target *-*-* } .-1 } */
      30  
      31  int a1[1] = { [1] = 0 }; /* { dg-error "array index in initializer exceeds array bounds" } */
      32  /* { dg-message "near init" "near" { target *-*-* } .-1 } */
      33  int a2[1] = { [-1] = 0 }; /* { dg-error "array index in initializer exceeds array bounds" } */
      34  /* { dg-message "near init" "near" { target *-*-* } .-1 } */
      35  int a3[1] = { [0 ... 1] = 0 }; /* { dg-error "array index range in initializer exceeds array bounds" } */
      36  /* { dg-message "near init" "near" { target *-*-* } .-1 } */
      37  int a4[2] = { [1 ... 0] = 0 }; /* { dg-error "empty index range in initializer" } */
      38  /* { dg-message "near init" "near" { target *-*-* } .-1 } */
      39  int a5[2] = { [0 ... 2] = 0 }; /* { dg-error "array index range in initializer exceeds array bounds" } */
      40  /* { dg-message "near init" "near" { target *-*-* } .-1 } */
      41  int a6[2] = { [-1 ... 1] = 0 }; /* { dg-error "array index in initializer exceeds array bounds" } */
      42  /* { dg-message "near init" "near" { target *-*-* } .-1 } */
      43  int a7[] = { [-1 ... 1] = 0 }; /* { dg-error "array index in initializer exceeds array bounds" } */
      44  /* { dg-message "near init" "near" { target *-*-* } .-1 } */