This is the mail archive of the gdb@sources.redhat.com mailing list for the GDB project.


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

[Fwd: -Wswitch vs -Wuninitialized]


Just FYI,

I've posted this to the GCC discussion list.  It is directly relevant to
the GDB group as I'm already seeing this problem.  The file remote.c
contains a case very like the example ``code#2''.

I'm trying to get a better understanding of the underlying issues so
that, like -Wunused vs -Wunused-params, we do more than just cover our
eyes and ignore the problem :-)

	enjoy,
		Andrew


Hello,

I'm looking at the interaction between -Wswitch and -Wuninitialized. 
Given the ``buggy'' code:

  code#1
	enum e { E_A, E_B, E_C };
	int
	foo (enum e ev)
	{
	  int i;
	  switch (ev)
	    {
	    case E_A: i = 1; break;
	    case E_B: i = 2; break;
	    }
	  return i;
	}

GCC (2.95.2 19991024) reports:

	enumeration value `E_C' not handled in switch
	`i' might be used uninitialized in this function

Adding the missing enum vis:

  code#2
	...
	  switch (ev)
	    {
	    case E_A: i = 1; break;
	    case E_B: i = 2; break;
	    case E_C: i = 3; break;
	    }
	...

still gives the warning:

	`i' might be used uninitialized in this function

If instead a ``default:'' case had been present:

  code#3
	  switch (ev)
	    {
	    case E_A: i = 1; break;
	    case E_B: i = 2; break;
	    default: abort (); /* bad switch */
	    }

the -Wuninitialized issue is addressed (GCC knows that all branches are
covered).  Unfortunatly, it also supresses the -Wswitch warning - which
may still be a second bug.

Has anyone looked at refining the way -Wswitch works so that it is still
useful in cases such as the above?  Alternativly, is there a suggested
coding pratice that addreses this?

	enjoy,
		Andrew




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