Enum conversion warning when one signed and other unsigned.
authorMicah Weston <micahsweston@gmail.com>
Mon, 9 May 2022 14:15:10 +0000 (10:15 -0400)
committerAaron Ballman <aaron@aaronballman.com>
Mon, 9 May 2022 14:16:19 +0000 (10:16 -0400)
commit882915df61e33f3a2b7f58e52f572717e1c11499
treebd1af402700384b864b8718de1d98926dbb35b1b
parentd9e6b5df74f54a7cf21a419f737d922040c1ed08
Enum conversion warning when one signed and other unsigned.

Ensures an -Wenum-conversion warning happens when one of the enums is
signed and the other is unsigned. Also adds a test file to verify these
warnings.

This warning would not happen since the -Wsign-conversion would make a
diagnostic then return, never allowing the -Wenum-conversion checks.

For example:

C
enum PE { P = -1 };
enum NE { N };
enum NE conv(enum PE E) { return E; }
Before this would only create a diagnostic with -Wsign-conversion and
never on -Wenum-conversion. Now it will create a diagnostic for both
-Wsign-conversion and -Wenum-conversion.

I could change it to just warn on -Wenum-conversion as that was what I
initially did. Seeing PR35200 (or GitHub Issue 316268), I let both
diagnostics check so that the sign conversion could generate a warning.
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaChecking.cpp
clang/test/Sema/enum-enum-conversion.c [new file with mode: 0644]
clang/test/Sema/enum-sign-conversion.c