zserio
zserio copied to clipboard
Consider command line argument to enable "optional clause warnings" for ternary operator
Currently, the optional clause warning is not fired if ternary operator is used. This is because zserio is not able to check correctness of such expression.
Example:
struct Data
{
bool hasId;
uint32 id if hasId;
function uint32 Cond()
{
return id; // WARNING! Field 'id' is optional and it does not have to be available!
}
};
struct Data
{
bool hasId;
uint32 id if hasId;
function uint32 Cond()
{
return (hasId) ? id : 0; // NO WARNING! Because ternary operator is used but it is correct.
}
};
struct Data
{
bool hasId;
uint32 id if hasId;
function uint32 Cond()
{
return (id != 0) ? id : 0; // NO WARNING! Because ternary operator is used but it is wrong.
}
};
We suggest to enable optional clause warnings for ternary operator as well but only on request by command line argument. For more information see #360 or #51.
It is just enough to create warning for this with special unique specifier (tag).