Fix type casts from initializer lists to arrays of unspecified size

This commit is contained in:
Michael Tautschnig 2017-08-18 16:27:24 +00:00
parent 1fa569fd17
commit 3273bf5b97
3 changed files with 21 additions and 1 deletions

View File

@ -0,0 +1,6 @@
int main()
{
int A[(sizeof((int[]){1, 2, 3})==3*sizeof(int))?1:-1];
return 0;
}

View File

@ -0,0 +1,7 @@
CORE
main.c
^EXIT=0$
^SIGNAL=0$
--
^CONVERSION ERROR$

View File

@ -1100,7 +1100,14 @@ void c_typecheck_baset::typecheck_expr_typecast(exprt &expr)
// or an expression for a pointer or scalar.
// We produce a compound_literal expression.
exprt tmp(ID_compound_literal, expr.type());
tmp.move_to_operands(op);
tmp.copy_to_operands(op);
// handle the case of TYPE being an array with unspecified size
if(op.id()==ID_array &&
expr.type().id()==ID_array &&
to_array_type(expr.type()).size().is_nil())
tmp.type()=op.type();
expr=tmp;
expr.set(ID_C_lvalue, true); // these are l-values
return;