zserio icon indicating copy to clipboard operation
zserio copied to clipboard

Signed comparison between literal and field in C++

Open mikir opened this issue 4 years ago • 0 comments

Consider the following schema:

struct Test
{
    varint32  id : id <= 268435454;
};

The C++ generates the construct get(Id) <= 268435454UL which fires the C++ warning comparison between signed and unsigned integer expressions [-Wsign-compare].

The generator should not use unsigned literals in signed comparison because if one operator is unsigned in C++, all other operators are cast to unsigned:

(-1 > 1) => false
(-1 > 1U) => true

mikir avatar Jun 10 '20 10:06 mikir