# V2006. Implicit type conversion from enum type to integer type.

This diagnostic rule was added at users' request.

The analyzer allows you to detect all implicit conversions of enum to integer types.

The V2006 diagnostic rule helps you refactor your code and, in some cases, detect errors.

Here is an example of a construction that the analyzer will issue this diagnostic message to:

    enum Orientation {
      Horizontal = 0x1,
      Vertical = 0x2
    };
    Orientation orientation = Horizontal;
    int pos = orientation; // V2006

The V2006 diagnostic message is not issued in the following cases.

First. The analyzer does not warn you when an enumerator is compared with a variable of type, such as 'int'. Although the constant is implicitly cast to the 'int' type before the comparison, this case is too common to issue a warning.

    int pos = foo();
    if (pos == Vertical) // Ok
    {
      ....
    }

Second. Two enumerators of the enumerated type are compared:

    enum E
    {
      ZERO, ONE, TWO
    };

    void foo(E e1, E e2)
    {
      if (e1 == e2)      // ok
        ....
      else if (e1 > e2)  // ok
        ....
      else if (e1 != e2) // ok
        ....
    }

Third. An implicit type conversion occurs when an enumerator is shifted to initialize another enumerator or array elements:

    enum E
    {
      FIRST_BIT = 1,
      SECOND_BIT = FISRT_BIT << 1, // ok
      THIRD_BIT = FISRT_BIT << 2,  // ok
      ....
    };
    int A[3] = {
      FIRST_BIT,
      FIRST_BIT << 1, // ok
      FIRST_BIT << 2  // ok
    };