Skip to content

Commit 36fa6f4

Browse files
authored
Merge pull request #5727 from tautschnig/array-init
Array initializers can also be compound literals
2 parents b72af07 + ad373ab commit 36fa6f4

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

regression/cbmc/compound_literal1/main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ union U { float f; int i; };
66
// global scope, static lifetime
77
int *global_scope_literal=&(int){ 43 };
88

9+
int array[3] = (int[3]){1, 2, 3};
10+
911
int main()
1012
{
1113
assert(*global_scope_literal==43);

src/ansi-c/c_typecheck_initializer.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ void c_typecheck_baset::do_initializer(
3838
"any array must have a size");
3939

4040
// we don't allow initialisation with symbols of array type
41-
if(result.id() != ID_array && result.id() != ID_array_of)
41+
if(
42+
result.id() != ID_array && result.id() != ID_array_of &&
43+
result.id() != ID_compound_literal)
4244
{
4345
error().source_location = result.source_location();
4446
error() << "invalid array initializer " << to_string(result)

0 commit comments

Comments
 (0)