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/35207] New: gcc does not warn when wrong value is passed to enumerated data type


Options given while compiling : -Wall
Complete command line: gcc -Wall <file name>

#include<stdio.h>

typedef enum {
   ALL_COLORS,
   GREEN_COLOR,
   RED_COLOR,
   BLUE_COLOR
}colors_e;

typedef struct _model {
   colors_e model_color;
}model;

void test_valid(model *ptr)
{
      switch(ptr->model_color) {
           case ALL_COLORS:
                      printf("All colors is choosed\n");
                      break;
           case GREEN_COLOR:
                      printf("Green color is choosed\n");
                      break;
           case RED_COLOR:
                      printf("Red color is choosed\n");
                      break;
           case BLUE_COLOR:
                      printf("Blue color is choosed\n");
                      break;
           default:
                      printf("Wrong color is choosed\n");
      }
}

int main()
{
   model t;

   t.model_color = 5;
   test_valid(&t);
   return 0;
}

In the above program I am passing invalid value to the structure member which
is an enumerated data type. While compiling I was expecting a warning, but I
did not get any warning. However, in the function a 'default' case is handled
to handle this type of invalid values, but this happens only when executing. Is
it possible to report a warning during compilation itself ?


-- 
           Summary: gcc does not warn when wrong value is passed to
                    enumerated data type
           Product: gcc
           Version: 4.0.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: venk2ksubbu at gmail dot com
  GCC host triplet: i386-redhat-linux


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


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