On 05/09/2017 07:04 PM, Martin Sebor wrote:
>>>
> 
> -Wassign-enum is a Clang warning too, it just isn't included in
> either -Wall or -Wextra.  It warns when a constant is assigned
> to a variable of an enumerated type and is not representable in
> it.  I enhanced it for GCC to also warn when the constant doesn't
> correspond to an enumerator in the type,

Note that that means that the warning will trigger in the common use
case of using enums as bit flags, like:

enum flags
  {
    F1 = 1 << 1,
    F2 = 1 << 2,
    F3 = 1 << 3
  };

void foo ()
{
  enum flags f = 0;
  f = F1 | F2;
}

I was going to suggest adding an attribute to mark such enum
types, and it turns out that Clang has one already:
  https://clang.llvm.org/docs/AttributeReference.html#flag-enum

So, IMHO if we add the warning, IWBN to add the attribute as well.

> but I'm starting to think
> that rather than adding yet another option to GCC it might be better
> to extend your -Wenum-conversion once it's committed to cover those
> cases (and also to avoid issuing multiple warnings for essentially
> the same problem).  Let me ponder that some more.

Thanks,
Pedro Alves

Reply via email to