public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/35207]  New: gcc does not warn when wrong value is passed to enumerated data type
@ 2008-02-15  5:57 venk2ksubbu at gmail dot com
  2008-02-15  9:44 ` [Bug c/35207] " rguenth at gcc dot gnu dot org
  2008-02-15 10:25 ` manu at gcc dot gnu dot org
  0 siblings, 2 replies; 3+ messages in thread
From: venk2ksubbu at gmail dot com @ 2008-02-15  5:57 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c/35207] gcc does not warn when wrong value is passed to enumerated data type
  2008-02-15  5:57 [Bug c/35207] New: gcc does not warn when wrong value is passed to enumerated data type venk2ksubbu at gmail dot com
@ 2008-02-15  9:44 ` rguenth at gcc dot gnu dot org
  2008-02-15 10:25 ` manu at gcc dot gnu dot org
  1 sibling, 0 replies; 3+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-02-15  9:44 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from rguenth at gcc dot gnu dot org  2008-02-15 09:43 -------
We can add a warning to follow C++ which would reject this code.  EDG for
example says

t.c(38): warning #188: enumerated type mixed with another type
     t.model_color = 5;

but the C std says the enum can hold all values represented by the underlying
type, so the code is behaving as required.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement


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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c/35207] gcc does not warn when wrong value is passed to enumerated data type
  2008-02-15  5:57 [Bug c/35207] New: gcc does not warn when wrong value is passed to enumerated data type venk2ksubbu at gmail dot com
  2008-02-15  9:44 ` [Bug c/35207] " rguenth at gcc dot gnu dot org
@ 2008-02-15 10:25 ` manu at gcc dot gnu dot org
  1 sibling, 0 replies; 3+ messages in thread
From: manu at gcc dot gnu dot org @ 2008-02-15 10:25 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from manu at gcc dot gnu dot org  2008-02-15 10:24 -------


*** This bug has been marked as a duplicate of 7654 ***


-- 

manu at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |manu at gcc dot gnu dot org
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |DUPLICATE


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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-02-15 10:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-15  5:57 [Bug c/35207] New: gcc does not warn when wrong value is passed to enumerated data type venk2ksubbu at gmail dot com
2008-02-15  9:44 ` [Bug c/35207] " rguenth at gcc dot gnu dot org
2008-02-15 10:25 ` manu at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).