This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/52763] New: Warning if compare between enum and non-enum type


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

             Bug #: 52763
           Summary: Warning if compare between enum and non-enum type
    Classification: Unclassified
           Product: gcc
           Version: 4.6.3
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: gccreports@gmx-topmail.de


Hi, 

the following program doesn't create a warning. It would be nice to get an
warning each time a enumeration type is compared to a non enumeration type,
because it forces better readable code (at least in my opinion).

I compiled this with 'g++ -Wall -Wextra -Wconversion -Werror'.

Best regards,
  Mikka


typedef enum {
  NONE = 0, ONE = 1, TWO = 2
} tEnumType;

int main(void){
  tEnumType var1 = TWO;
  //Warn here, because we compare an enum to a non-enum type (1)
  //should be 'if (var1 == ONE)'
  if (var1 == 1)
    return 1;
  else
    return 0;
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]