[Bug c/7654] warn if an enum is being assigned a non enum value
msebor at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Thu May 11 23:53:00 GMT 2017
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=7654
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|SUSPENDED |NEW
CC| |msebor at gcc dot gnu.org
See Also| |https://gcc.gnu.org/bugzill
| |a/show_bug.cgi?id=78736
--- Comment #11 from Martin Sebor <msebor at gcc dot gnu.org> ---
I'll confirm this ancient request.
Bug 78736 asks for something similar, and I'm working on enhancing the solution
there even further (to diagnose assigning constants that don't have a
corresponding enumerator in the destination type). I'll add that on the
following slightly modified test case Clang issues the warnings below:
$ cat t.C && clang -S -Wall -Wextra -Weverything -xc t.C
void f (int i)
{
enum e1 { e1a, e1b };
enum e1 e1v;
enum e2 { e2a, e2b };
enum e2 e2v;
e1v = 1; // no warning
e1v = 3; // warning
e1v = e1a; // ok
e2v = e1v; // warning
i = e1v; // ok I guess
e2v = i; // warning
}
t.C:9:9: warning: integer constant not in range of enumerated type 'enum e1'
[-Wassign-enum]
e1v = 3; // warning
^
t.C:11:9: warning: implicit conversion from enumeration type 'enum e1' to
different enumeration type 'enum e2' [-Wenum-conversion]
e2v = e1v; // warning
~ ^~~
t.C:13:9: warning: implicit conversion changes signedness: 'int' to 'enum e2'
[-Wsign-conversion]
e2v = i; // warning
~ ^
t.C:1:6: warning: no previous prototype for function 'f' [-Wmissing-prototypes]
void f (int i)
^
4 warnings
More information about the Gcc-bugs
mailing list