c-typeck.c (set_init_index): Allow array designators that are not integer constant expressions with a...

* c-typeck.c (set_init_index): Allow array designators that are
	not integer constant expressions with a pedwarn if pedantic.

testsuite:
	* gcc.dg/array-const-1.c, gcc.dg/array-const-2.c,
	gcc.dg/array-const-3.c: New tests.

From-SVN: r146741
This commit is contained in:
Joseph Myers 2009-04-24 18:24:32 +01:00 committed by Joseph Myers
parent bda61b12c2
commit 2b6da65c33
6 changed files with 54 additions and 0 deletions

View File

@ -1,3 +1,8 @@
2009-04-24 Joseph Myers <joseph@codesourcery.com>
* c-typeck.c (set_init_index): Allow array designators that are
not integer constant expressions with a pedwarn if pedantic.
2009-04-24 Bernd Schmidt <bernd.schmidt@analog.com>
* simplify-rtx.c (simplify_binary_operation_1, case AND): Result is

View File

@ -6421,6 +6421,24 @@ set_init_index (tree first, tree last)
return;
}
if (TREE_CODE (first) != INTEGER_CST)
{
first = c_fully_fold (first, false, NULL);
if (TREE_CODE (first) == INTEGER_CST)
pedwarn_init (input_location, OPT_pedantic,
"array index in initializer is not "
"an integer constant expression");
}
if (last && TREE_CODE (last) != INTEGER_CST)
{
last = c_fully_fold (last, false, NULL);
if (TREE_CODE (last) == INTEGER_CST)
pedwarn_init (input_location, OPT_pedantic,
"array index in initializer is not "
"an integer constant expression");
}
if (TREE_CODE (first) != INTEGER_CST)
error_init ("nonconstant array index in initializer");
else if (last != 0 && TREE_CODE (last) != INTEGER_CST)

View File

@ -1,3 +1,8 @@
2009-04-24 Joseph Myers <joseph@codesourcery.com>
* gcc.dg/array-const-1.c, gcc.dg/array-const-2.c,
gcc.dg/array-const-3.c: New tests.
2009-04-24 Ian Lance Taylor <iant@google.com>
* gcc.dg/Wcxx-compat-4.c: New testcase.

View File

@ -0,0 +1,8 @@
/* Test for array designators not integer constant expressions but
folding to integer constants (used in Linux kernel,
<http://gcc.gnu.org/ml/gcc/2009-04/msg00611.html>). */
/* { dg-do compile } */
/* { dg-options "-std=gnu99" } */
extern int i;
int a[] = { [1 ? 1 : i] = 0 };

View File

@ -0,0 +1,9 @@
/* Test for array designators not integer constant expressions but
folding to integer constants (used in Linux kernel,
<http://gcc.gnu.org/ml/gcc/2009-04/msg00611.html>). */
/* { dg-do compile } */
/* { dg-options "-std=gnu99 -pedantic" } */
extern int i;
int a[] = { [1 ? 1 : i] = 0 }; /* { dg-warning "array index in initializer is not an integer constant expression" } */
/* { dg-warning "near initialization" "near init" { target *-*-* } 8 } */

View File

@ -0,0 +1,9 @@
/* Test for array designators not integer constant expressions but
folding to integer constants (used in Linux kernel,
<http://gcc.gnu.org/ml/gcc/2009-04/msg00611.html>). */
/* { dg-do compile } */
/* { dg-options "-std=gnu99 -pedantic-errors" } */
extern int i;
int a[] = { [1 ? 1 : i] = 0 }; /* { dg-error "array index in initializer is not an integer constant expression" } */
/* { dg-error "near initialization" "near init" { target *-*-* } 8 } */