-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle array initialization with a non-array gracefully
clang -Wall says: Struct_Initialization1/main.c:16:38: warning: suggest braces around initialization of subobject [-Wmissing-braces] struct _classinfo nullclass1 = { 42, 1, 2, 3, 4 }; ^~~~ { } and then constructs a suitable object. Our implementation now attempts to build an initializer list if a variable-length array is encountered; if this succeeds, the same suitable object is constructed. Variable-length arrays in the middle of a struct are not permitted (neither by GCC nor Clang or our C front-end).
- Loading branch information
1 parent
13a7538
commit 9740142
Showing
7 changed files
with
105 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
KNOWNBUG | ||
CORE | ||
main.c | ||
|
||
^EXIT=0$ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#define STATIC_ASSERT(condition) \ | ||
int some_array##__LINE__[(condition) ? 1 : -1] | ||
|
||
struct A { | ||
int x; | ||
int y; | ||
int arr[]; | ||
}; | ||
|
||
struct _classinfo { | ||
char a; | ||
struct A s; | ||
int *interfaces[]; | ||
}; | ||
|
||
struct _classinfo nullclass1 = { 42, 1, 2, 0, 3, 4 }; | ||
struct _classinfo nullclass2 = { 42, { 1, 2, 0 }, { 3, 4 } }; | ||
|
||
STATIC_ASSERT(sizeof(nullclass1)==sizeof(struct _classinfo)); | ||
STATIC_ASSERT(sizeof(nullclass2)==sizeof(struct _classinfo)); | ||
|
||
int main() | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
CORE | ||
main.c | ||
|
||
^EXIT=(64|1)$ | ||
^SIGNAL=0$ | ||
^CONVERSION ERROR$ | ||
-- | ||
^warning: ignoring | ||
-- | ||
variable-length arrays in the middle of a struct are not permitted |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters