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/7652] -Wswitch-break : Warn if a switch case falls through


------- Additional Comments From brendan at zen dot org  2004-07-29 09:43 -------
An alternative between "warn about all fall-throughs" and "never do it" would 
be quite useful.  If you have 
  case 0: 
  case 1: 
     foo(); 
  default: 
     bar(); 
gcc could warn only on the 'case 1' line, since it will see that there are 
statements between it and the default beneath it without a 'break' intervening.  
The fact that 'case 0' falls into 'case 1' won't be warned, since there are no 
actions between them. 
 
Most of the time, users will have a good reason to do multiple cases, but less 
often will someone want  
	case 0: 
	   bar(i); 
	case 1: 
	   foo(i); 
	   break; 
For those instances, they'll probably not be using -Wswitch-break (defaulting 
to off) anyway.  At any rate, it'll much more common to make the mistake of 
omitting the break, compared to coding it to have statements between cases 
without 'break'.  My opinion, anyway. 
 
B 
 

-- 


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


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