Skip to content

Commit 3273bf5

Browse files
committed
Fix type casts from initializer lists to arrays of unspecified size
1 parent 1fa569f commit 3273bf5

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
int main()
2+
{
3+
int A[(sizeof((int[]){1, 2, 3})==3*sizeof(int))?1:-1];
4+
5+
return 0;
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
main.c
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^CONVERSION ERROR$

src/ansi-c/c_typecheck_expr.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -1100,7 +1100,14 @@ void c_typecheck_baset::typecheck_expr_typecast(exprt &expr)
11001100
// or an expression for a pointer or scalar.
11011101
// We produce a compound_literal expression.
11021102
exprt tmp(ID_compound_literal, expr.type());
1103-
tmp.move_to_operands(op);
1103+
tmp.copy_to_operands(op);
1104+
1105+
// handle the case of TYPE being an array with unspecified size
1106+
if(op.id()==ID_array &&
1107+
expr.type().id()==ID_array &&
1108+
to_array_type(expr.type()).size().is_nil())
1109+
tmp.type()=op.type();
1110+
11041111
expr=tmp;
11051112
expr.set(ID_C_lvalue, true); // these are l-values
11061113
return;

0 commit comments

Comments
 (0)