Report an error when void values are used in binary expressions.

These would previously be allowed, with the void value treated as if it was unsigned long.

Void values are still allowed for the second and third operands of the ?: operator, but only if they are both void. This is as required by the C standard.
This commit is contained in:
Stephen Heumann
2016-10-14 20:37:10 -05:00
parent 9558a88571
commit 89f1dbce9b

View File

@@ -321,14 +321,18 @@ UsualBinaryConversions := cgULong;
if lType^.kind = pointerType then if lType^.kind = pointerType then
lType := uLongPtr lType := uLongPtr
else if lType^.kind = scalarType then else if lType^.kind = scalarType then
if lType^.baseType = cgVoid then if lType^.baseType = cgVoid then begin
lType := uLongPtr; lType := uLongPtr;
Error(66);
end; {if}
rType := expressionType; rType := expressionType;
if rType^.kind = pointerType then if rType^.kind = pointerType then
rType := uLongPtr rType := uLongPtr
else if rType^.kind = scalarType then else if rType^.kind = scalarType then
if rType^.baseType = cgVoid then if rType^.baseType = cgVoid then begin
rType := uLongPtr; rType := uLongPtr;
Error(66);
end; {if}
if (lType^.kind = scalarType) and (rType^.kind = scalarType) then begin if (lType^.kind = scalarType) and (rType^.kind = scalarType) then begin
lt := Unary(lType^.baseType); lt := Unary(lType^.baseType);
rt := Unary(rType^.baseType); rt := Unary(rType^.baseType);
@@ -3580,7 +3584,13 @@ case tree^.token.kind of
tType := expressionType tType := expressionType
else else
tType := lType; tType := lType;
et := UsualBinaryConversions(lType); if (expressionType^.kind = scalarType)
and (expressionType^.baseType = cgVoid)
and (lType^.kind = scalarType)
and (lType^.baseType = cgVoid) then
et := cgVoid
else
et := UsualBinaryConversions(lType);
Gen0(pc_bno); Gen0(pc_bno);
Gen0t(pc_tri, et); Gen0t(pc_tri, et);
end; {else} end; {else}