zserio icon indicating copy to clipboard operation
zserio copied to clipboard

Consider command line argument to enable "optional clause warnings" for ternary operator

Open mikir opened this issue 3 years ago • 1 comments

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.

mikir avatar Feb 07 '22 13:02 mikir

It is just enough to create warning for this with special unique specifier (tag).

mikir avatar Oct 07 '22 10:10 mikir