https://gcc.gnu.org/bugzilla/show_bug.cgi?id=7654

Eric Gallager <egallager at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |egallager at gcc dot gnu.org

--- Comment #12 from Eric Gallager <egallager at gcc dot gnu.org> ---
(In reply to Martin Sebor from comment #11)
> 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

gcc now prints:

$ /usr/local/bin/gcc -c -S -Wall -Wextra -Wconversion -Wsign-conversion
-Wmissing-prototypes -pedantic -xc 7654.c
7654.c:1:6: warning: no previous prototype for 'f' [-Wmissing-prototypes]
    1 | void f (int i)
      |      ^
7654.c: In function 'f':
7654.c:11:6: warning: implicit conversion from 'enum e1' to 'enum e2'
[-Wenum-conversion]
   11 |  e2v = e1v; // warning
      |      ^
7654.c:6:10: warning: variable 'e2v' set but not used
[-Wunused-but-set-variable]
    6 |  enum e2 e2v;
      |          ^~~
$

so, gcc has -Wenum-conversion now, but it is still missing warnings from
-Wassign-enum and -Wsign-conversion on this testcase.

Reply via email to