summaryrefslogtreecommitdiffstats
path: root/clang/test/Sema
diff options
context:
space:
mode:
authorYunzhong Gao <Yunzhong_Gao@playstation.sony.com>2015-06-10 00:27:52 +0000
committerYunzhong Gao <Yunzhong_Gao@playstation.sony.com>2015-06-10 00:27:52 +0000
commitcb77930d6b20e53c735233eecf4572a1c30eb0c0 (patch)
tree74f8f3c0612aee5391a6cb5bbb5eb01c0a6d5be8 /clang/test/Sema
parent7912d9b8999266e55ff40e15d37fa458e66f436c (diff)
downloadbcm5719-llvm-cb77930d6b20e53c735233eecf4572a1c30eb0c0.tar.gz
bcm5719-llvm-cb77930d6b20e53c735233eecf4572a1c30eb0c0.zip
Implementing C99 partial re-initialization behavior (DR-253)
Based on previous discussion on the mailing list, clang currently lacks support for C99 partial re-initialization behavior: Reference: http://lists.cs.uiuc.edu/pipermail/cfe-dev/2013-April/029188.html Reference: http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_253.htm This patch attempts to fix this problem. Given the following code snippet, struct P1 { char x[6]; }; struct LP1 { struct P1 p1; }; struct LP1 l = { .p1 = { "foo" }, .p1.x[2] = 'x' }; // this example is adapted from the example for "struct fred x[]" in DR-253; // currently clang produces in l: { "\0\0x" }, // whereas gcc 4.8 produces { "fox" }; // with this fix, clang will also produce: { "fox" }; Differential Review: http://reviews.llvm.org/D5789 llvm-svn: 239446
Diffstat (limited to 'clang/test/Sema')
-rw-r--r--clang/test/Sema/designated-initializers.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/clang/test/Sema/designated-initializers.c b/clang/test/Sema/designated-initializers.c
index 6630da67c5b..a4582deb171 100644
--- a/clang/test/Sema/designated-initializers.c
+++ b/clang/test/Sema/designated-initializers.c
@@ -45,8 +45,8 @@ struct point array[10] = {
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 ... 5].y = 2.0, // expected-note 2 {{previous initialization is here}}
+ [4 ... 6] = { .x = 3, .y = 4.0 } // expected-warning 2 {{subobject initialization overrides initialization of other fields within its enclosing subobject}}
};
struct point array3[10] = {
@@ -129,11 +129,11 @@ int get8() { ++counter; return 8; }
void test() {
struct X xs[] = {
- [0] = (struct X){1, 2}, // expected-note{{previous initialization is here}}
+ [0] = (struct X){1, 2}, // expected-note 2 {{previous initialization is here}}
[0].c = 3, // expected-warning{{subobject initialization overrides initialization of other fields within its enclosing subobject}}
(struct X) {4, 5, 6}, // expected-note{{previous initialization is here}}
[1].b = get8(), // expected-warning{{subobject initialization overrides initialization of other fields within its enclosing subobject}}
- [0].b = 8
+ [0].b = 8 // expected-warning{{subobject initialization overrides initialization of other fields within its enclosing subobject}}
};
}
@@ -332,12 +332,22 @@ struct overwrite_string_struct {
int M;
} overwrite_string[] = {
{ { "foo" }, 1 }, // expected-note {{previous initialization is here}}
- [0].L[2] = 'x' // expected-warning{{initializer overrides prior initialization of this subobject}}
+ [0].L[2] = 'x' // expected-warning{{subobject initialization overrides initialization of other fields}}
};
struct overwrite_string_struct2 {
char L[6];
int M;
} overwrite_string2[] = {
- { { "foo" }, 1 },
- [0].L[4] = 'x' // no-warning
+ { { "foo" }, 1 }, // expected-note{{previous initialization is here}}
+ [0].L[4] = 'x' // expected-warning{{subobject initialization overrides initialization of other fields}}
};
+struct overwrite_string_struct
+overwrite_string3[] = {
+ "foo", 1, // expected-note{{previous initialization is here}}
+ [0].L[4] = 'x' // expected-warning{{subobject initialization overrides initialization of other fields}}
+};
+struct overwrite_string_struct
+overwrite_string4[] = {
+ { { 'f', 'o', 'o' }, 1 },
+ [0].L[4] = 'x' // no-warning
+};
OpenPOWER on IntegriCloud