[Bug c/7654] warn if an enum is being assigned a non enum value

2019-10-18 Thread egallager at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=7654

Eric Gallager  changed:

   What|Removed |Added

 CC||egallager at gcc dot gnu.org

--- Comment #12 from Eric Gallager  ---
(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.

[Bug c/7654] warn if an enum is being assigned a non enum value

2017-05-11 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=7654

Martin Sebor  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  ---
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

[Bug c/7654] warn if an enum is being assigned a non enum value

2008-08-24 Thread manu at gcc dot gnu dot org


--- Comment #10 from manu at gcc dot gnu dot org  2008-08-24 21:31 ---
I think we should mark as SUSPENDED those enhancement requests where there is
no consensus that we actually want the feature, even if a patch were available.
It would be a waste of time to implement this just to have it rejected.


-- 

manu at gcc dot gnu dot org changed:

   What|Removed |Added

 Status|NEW |SUSPENDED


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



[Bug c/7654] warn if an enum is being assigned a non enum value

2008-02-15 Thread manu at gcc dot gnu dot org


--- Comment #9 from manu at gcc dot gnu dot org  2008-02-15 10:36 ---
It is not clear whether we want such a warning or not (and in 6 years, just 2
people have suggested it not too loudly). But if we do:

* -Wstrict-enums seems a better name. It should be consistent and not handle
only assignments but also argument passing.
* An explicit cast should suppress the warning.
* The warning should not be enabled by -Wall and probably neither by -Wextra
because enums are *correctly* used as integers by C programmers.

It is also unclear whether we want to warn for any integer/enum assigned to a
different enum type or just for integers/enums outside the range of a
particular enum type.


-- 

manu at gcc dot gnu dot org changed:

   What|Removed |Added

Summary|-Wenum-assignment : Warn if |warn if an enum is being
   |an enum is being assigned a |assigned a non enum value
   |non enum value  |


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