diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-01-22 23:26:18 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-01-22 23:26:18 +0000 |
commit | d7fb85e8ad6f006537cd2eb2dfaba38268fb794f (patch) | |
tree | e260f9e4cff0e1ae3b7e3546cd9f7d83cd6bff09 /clang/test/Sema/designated-initializers.c | |
parent | 2e1cfd02679b8b2d4cdbe75344071389d006c631 (diff) | |
download | bcm5719-llvm-d7fb85e8ad6f006537cd2eb2dfaba38268fb794f.tar.gz bcm5719-llvm-d7fb85e8ad6f006537cd2eb2dfaba38268fb794f.zip |
Reimplement the handling of the "current object" in designator
initializers, so that we are within the appropriate subobject after
we've processed a multi-designator designation. We're matching GCC and
EDG's behavior on all examples I've found thus far.
*Huge* thanks to Eli Friedman for pointing out my fundamental
misunderstanding of "current object" in the C99 spec.
llvm-svn: 62812
Diffstat (limited to 'clang/test/Sema/designated-initializers.c')
-rw-r--r-- | clang/test/Sema/designated-initializers.c | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/clang/test/Sema/designated-initializers.c b/clang/test/Sema/designated-initializers.c index 5efb4444956..cc2c3468edc 100644 --- a/clang/test/Sema/designated-initializers.c +++ b/clang/test/Sema/designated-initializers.c @@ -1,5 +1,9 @@ // RUN: clang -fsyntax-only -verify %s +int complete_array_from_init[] = { 1, 2, [10] = 5, 1, 2, [5] = 2, 6 }; + +int complete_array_from_init_check[((sizeof(complete_array_from_init) / sizeof(int)) == 13)? 1 : -1]; + int iarray[10] = { [0] = 1, [1 ... 5] = 2, @@ -11,6 +15,9 @@ int iarray[10] = { int iarray2[10] = { [10] = 1, // expected-error{{array designator index (10) exceeds array bounds (10)}} +}; + +int iarray3[10] = { [5 ... 12] = 2 // expected-error{{array designator index (12) exceeds array bounds (10)}} }; @@ -23,7 +30,9 @@ struct point p1 = { .y = 1.0, x: 2.0, .a = 4.0, // expected-error{{field designator 'a' does not refer to any field in type 'struct point'}} +}; +struct point p2 = { [1] = 1.0 // expected-error{{array designator cannot initialize non-array type}} }; @@ -31,9 +40,15 @@ struct point array[10] = { [0].x = 1.0, [1].y = 2.0, [2].z = 3.0, // expected-error{{field designator 'z' does not refer to any field in type 'struct point'}} +}; + +struct point array2[10] = { [10].x = 2.0, // expected-error{{array designator index (10) exceeds array bounds (10)}} [4 ... 5].y = 2.0, - [4 ... 6] = { .x = 3, .y = 4.0 }, + [4 ... 6] = { .x = 3, .y = 4.0 } +}; + +struct point array3[10] = { .x = 5 // expected-error{{field designator cannot initialize a non-struct, non-union type}} }; @@ -76,3 +91,24 @@ struct translator { .wonky = { 0 } }; +int anint; +struct {int x,*y;} z[] = {[0].x = 2, &z[0].x}; + +struct outer { struct inner { int x, *y; } in, *inp; } zz[] = { + [0].in.x = 2, &zz[0].in.x, &zz[0].in, + 0, &anint, &zz[1].in, + [3].in = { .y = &anint, .x = 17 }, + [7].in.y = &anint, &zz[0].in, + [4].in.y = &anint, [5].in.x = 12 +}; + +int zz_sizecheck[sizeof(zz) / sizeof(struct outer) == 8? 1 : -1 ]; + +struct disklabel_ops { + struct {} type; + int labelsize; +}; + +struct disklabel_ops disklabel64_ops = { + .labelsize = sizeof(struct disklabel_ops) +}; |