Skip to content

Array initializers can also be compound literals #5727

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions regression/cbmc/compound_literal1/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ union U { float f; int i; };
// global scope, static lifetime
int *global_scope_literal=&(int){ 43 };

int array[3] = (int[3]){1, 2, 3};

int main()
{
assert(*global_scope_literal==43);
Expand Down
4 changes: 3 additions & 1 deletion src/ansi-c/c_typecheck_initializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ void c_typecheck_baset::do_initializer(
"any array must have a size");

// we don't allow initialisation with symbols of array type
if(result.id() != ID_array && result.id() != ID_array_of)
if(
result.id() != ID_array && result.id() != ID_array_of &&
result.id() != ID_compound_literal)
{
error().source_location = result.source_location();
error() << "invalid array initializer " << to_string(result)
Expand Down