diff options
author | Jakub Jelinek <jakub@redhat.com> | 2001-01-13 00:18:05 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2001-01-13 00:18:05 +0100 |
commit | 8b6a5902b5588d5e3e30ff2822655eec304345df (patch) | |
tree | 61018fce6476697759fec1b7443adbb9e7cc463d /gcc/testsuite/gcc.dg/c99-init-2.c | |
parent | fafc249b1bdd385ce0c45d2696ad7c1c09c9b2cb (diff) | |
download | gcc-8b6a5902b5588d5e3e30ff2822655eec304345df.zip gcc-8b6a5902b5588d5e3e30ff2822655eec304345df.tar.gz gcc-8b6a5902b5588d5e3e30ff2822655eec304345df.tar.bz2 |
c-typeck.c (store_init_value): Don't require constant initializer elements with -pedantic -std=c99.
* c-typeck.c (store_init_value): Don't require constant initializer
elements with -pedantic -std=c99.
(digest_init): Change error about non-constant initializer elements
into pedwarn.
(constructor_range_end): Remove.
(constructor_incremental, designator_depth,
designator_errorneous): New variables.
(struct constructor_stack): Remove range_end, add incremental.
(struct constructor_range_stack, constructor_range_stack): New.
(struct initializer_stack): Add constructor_range_stack.
(finish_init): Set it.
(start_init): Likewise. require_constant_elements for non-static
trees only if not flag_isoc99.
(really_start_incremental_init): Remove constructor_range_end, add
constructor_incremental.
(pop_init_level): Likewise.
(push_init_level): Likewise. If implicit and the subobject had some
value set already, preinitialize the level with it.
Warn about missing braces only if not pushing due to designators.
(set_designator, push_range_stack): New functions.
(set_init_label): Use them.
(set_init_index): Likewise. Remove constructor_range_end.
Error if designator index is outside of array bounds.
(add_pending_init): Compare values of purpose index trees, not the
trees themselves. Allow overwriting of already initialized element.
Issue a warning if it had side-effects.
(set_nonincremental_init, set_nonincremental_init_from_string): New
functions.
(pending_init_member): Rename to...
(find_init_member): ...this function. Call set_nonincremental_init
if necessary. Compare values of purpose index trees, not the trees
themselves. Return the actual value, not just non-zero if something
is found.
(output_init_element): Remove checks for duplicates.
If field has zero size, only check the initializer for correctness.
Call set_nonincremental_init if necessary. Push RECORD/ARRAY into AVL
if constructor_incremental is zero. Change error about initializers
not computable at load time into pedwarn.
(output_pending_init_elements): Compare bit positions, not
FIELD_DECLs to take into account zero-sized fields.
(process_init_element): Use constructor_range_stack to fill all
ranges in the designator lists from current level up.
* extend.texi: Update documentation for labeled elements.
* gcc.c-torture/execute/20000801-3.x: Remove.
* gcc.dg/c90-init-1.c: New test.
* gcc.dg/c99-init-1.c: New test.
* gcc.dg/c99-init-2.c: New test.
* gcc.dg/gnu99-init-1.c: New test.
From-SVN: r38968
Diffstat (limited to 'gcc/testsuite/gcc.dg/c99-init-2.c')
-rw-r--r-- | gcc/testsuite/gcc.dg/c99-init-2.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/c99-init-2.c b/gcc/testsuite/gcc.dg/c99-init-2.c new file mode 100644 index 0000000..d3a331f --- /dev/null +++ b/gcc/testsuite/gcc.dg/c99-init-2.c @@ -0,0 +1,30 @@ +/* Test for C99 designated initializer warnings and errors */ +/* Origin: Jakub Jelinek <jakub@redhat.com> */ +/* { dg-do compile } */ +/* { dg-options "-std=iso9899:1999 -Wall -pedantic-errors" } */ + +typedef struct { + int B; + short C[2]; +} A; +A a = { [2] = 1 }; /* { dg-error "(array index in non-array)|(near initialization)" } */ +int b[] = { .B = 1 }; /* { dg-error "(field name not in record)|(near initialization)" } */ +A c[] = { [0].D = 1 }; /* { dg-error "unknown field" } */ +int d; +int e = { d++ }; /* { dg-error "(is not constant)|(near initialization)" } */ +A f[2] = { [0].C[0] = 1, [2] = { 2, { 1, 2 } } };/* { dg-error "(array index in initializer exceeds array bounds)|(near initialization)" } */ +int g[4] = { [1] = 1, 2, [6] = 5 }; /* { dg-error "(array index in initializer exceeds array bounds)|(near initialization)" } */ +int h[] = { [0 ... 3] = 5 }; /* { dg-error "forbids specifying range of elements" } */ +int i[] = { [2] 4 }; /* { dg-error "use of designated initializer without" } */ +A j = { B: 2 }; /* { dg-error "use of designated initializer with " } */ + +void foo (int *, A *); + +void bar (void) +{ + int a[] = { d++, [0] = 1 }; /* { dg-warning "(initialized field with side-effects overwritten)|(near initialization)" } */ + A b = { 1, { d++, 2 }, .C[0] = 3 };/* { dg-warning "(initialized field with side-effects overwritten)|(near initialization)" } */ + A c = { d++, { 2, 3 }, .B = 4 }; /* { dg-warning "(initialized field with side-effects overwritten)|(near initialization)" } */ + + foo (a, d ? &b : &c); +} |