On 2016-05-05 09:32, Fabien COELHO wrote:
I note that C99 specifically mentions this as something a compiler
might warn about: [...]

Indeed. Neither gcc nor clang emit such warnings... but they might some
day, which would be a blow for my suggestion!

For what it's worth, newer versions of clang can emit useful warnings for cases like this:

int main(void) {
        enum test { FOUR = 4 };
        enum incompatible { INCOMPATIBLE_FOUR = 4 };
        enum test variable;
        variable = INCOMPATIBLE_FOUR;
        variable = 5;
        variable = 4;
        variable = 3;
        
        return 0;
}

enum.c:5:13: warning: implicit conversion from enumeration type 'enum incompatible' to different enumeration type 'enum test' [-Wenum-conversion]
        variable = INCOMPATIBLE_FOUR;
                 ~ ^~~~~~~~~~~~~~~~~
enum.c:6:13: warning: integer constant not in range of enumerated type 'enum test' [-Wassign-enum]
        variable = 5;
                   ^
enum.c:8:13: warning: integer constant not in range of enumerated type 'enum test' [-Wassign-enum]
        variable = 3;
                   ^
3 warnings generated.

So with -Wenum-conversion -Wassign-enum you could treat enum types as distinct and incompatible with each other.



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to