diff options
| author | jsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-07-21 23:51:29 +0000 |
|---|---|---|
| committer | jsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-07-21 23:51:29 +0000 |
| commit | a250ed2ee693d37316a0fef984e582b017c76fc6 (patch) | |
| tree | 718518dc062937fb49e610bc36b58dcaa5c7def1 /gcc | |
| parent | 3ad5f027d89dd828eff822371e1791f520d83c41 (diff) | |
| download | ppe42-gcc-a250ed2ee693d37316a0fef984e582b017c76fc6.tar.gz ppe42-gcc-a250ed2ee693d37316a0fef984e582b017c76fc6.zip | |
* c-typeck.c (set_init_index): Require designator to be of integer
type.
testsuite:
* gcc.dg/c99-init-3.c, gcc.dg/gnu99-init-2.c: New tests.
* gcc.dg/noncompile/921102-1.c: Update expected error message.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@85023 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc')
| -rw-r--r-- | gcc/ChangeLog | 5 | ||||
| -rw-r--r-- | gcc/c-typeck.c | 7 | ||||
| -rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
| -rw-r--r-- | gcc/testsuite/gcc.dg/c99-init-3.c | 8 | ||||
| -rw-r--r-- | gcc/testsuite/gcc.dg/gnu99-init-2.c | 11 | ||||
| -rw-r--r-- | gcc/testsuite/gcc.dg/noncompile/921102-1.c | 2 |
6 files changed, 37 insertions, 1 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 16fa6573ca8..00f2261e63f 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,10 @@ 2004-07-22 Joseph S. Myers <jsm@polyomino.org.uk> + * c-typeck.c (set_init_index): Require designator to be of integer + type. + +2004-07-22 Joseph S. Myers <jsm@polyomino.org.uk> + PR c/11250 * c-parse.in (init): Change to exprtype. (primary): Set original_code for STRING to STRING_CST. diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index 9c22b8b0cf0..04ed0684dbe 100644 --- a/gcc/c-typeck.c +++ b/gcc/c-typeck.c @@ -4956,6 +4956,13 @@ set_init_index (tree first, tree last) designator_errorneous = 1; + if (!INTEGRAL_TYPE_P (TREE_TYPE (first)) + || (last && !INTEGRAL_TYPE_P (TREE_TYPE (last)))) + { + error_init ("array index in initializer not of integer type"); + return; + } + while ((TREE_CODE (first) == NOP_EXPR || TREE_CODE (first) == CONVERT_EXPR || TREE_CODE (first) == NON_LVALUE_EXPR) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d199ab1228b..b03d923cd21 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,10 @@ 2004-07-22 Joseph S. Myers <jsm@polyomino.org.uk> + * gcc.dg/c99-init-3.c, gcc.dg/gnu99-init-2.c: New tests. + * gcc.dg/noncompile/921102-1.c: Update expected error message. + +2004-07-22 Joseph S. Myers <jsm@polyomino.org.uk> + PR c/11250 * gcc.dg/init-string-1.c: New test. diff --git a/gcc/testsuite/gcc.dg/c99-init-3.c b/gcc/testsuite/gcc.dg/c99-init-3.c new file mode 100644 index 00000000000..9aca19acc0b --- /dev/null +++ b/gcc/testsuite/gcc.dg/c99-init-3.c @@ -0,0 +1,8 @@ +/* Test for designated initializers: array designators must be of + integer type. */ +/* Origin: Joseph Myers <jsm@polyomino.org.uk> */ +/* { dg-do compile } */ +/* { dg-options "-std=iso9899:1999 -pedantic-errors" } */ + +int a[] = { [(void *)0] = 1 }; /* { dg-bogus "warning" "warning in place of error" } */ +/* { dg-error "integer type|near init" "pointer designator" { target *-*-* } 7 } */ diff --git a/gcc/testsuite/gcc.dg/gnu99-init-2.c b/gcc/testsuite/gcc.dg/gnu99-init-2.c new file mode 100644 index 00000000000..a4728a60884 --- /dev/null +++ b/gcc/testsuite/gcc.dg/gnu99-init-2.c @@ -0,0 +1,11 @@ +/* Test for designated initializers: array designators must be of + integer type. Test for index ranges (GNU extension). */ +/* Origin: Joseph Myers <jsm@polyomino.org.uk> */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99" } */ + +int a[] = { [(void *)0 ... 0] = 1 }; /* { dg-bogus "warning" "warning in place of error" } */ +/* { dg-error "integer type|near init" "pointer designator" { target *-*-* } 7 } */ + +int b[] = { [0 ... (void *)0] = 1 }; /* { dg-bogus "warning" "warning in place of error" } */ +/* { dg-error "integer type|near init" "pointer designator" { target *-*-* } 10 } */ diff --git a/gcc/testsuite/gcc.dg/noncompile/921102-1.c b/gcc/testsuite/gcc.dg/noncompile/921102-1.c index 8b66f712ef7..ef04b1b2aae 100644 --- a/gcc/testsuite/gcc.dg/noncompile/921102-1.c +++ b/gcc/testsuite/gcc.dg/noncompile/921102-1.c @@ -1 +1 @@ -int x[]={[0.3 ... 4.6]9}; /* { dg-error "nonconstant array|near init" } */ +int x[]={[0.3 ... 4.6]9}; /* { dg-error "not of integer type|near init" } */ |

