Bug 71110 - label "caseN" should be warned about
Summary: label "caseN" should be warned about
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 5.2.1
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2016-05-13 20:59 UTC by Hage Ropo
Modified: 2016-12-15 21:31 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2016-05-13 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Hage Ropo 2016-05-13 20:59:17 UTC
The Bug is Regarding `case value`. I have commented the bug in the program below.

#include <stdio.h>
   
int main()
{
   
 int n = 0;
   
 switch(n)
 {
  
  case 1:
    printf("Foo.\n");
    break;


  /* The following Syntax Error is not being detected, i.e no space between               'case' & 2 */

  case2:  
    printf("Bar.\n");
    break;

  default:
    printf("Bruhh.\n");
   }
  
  return 0;

 }


Thanks, 
Hage Ropo
Comment 1 Andrew Pinski 2016-05-13 21:02:31 UTC
case2: is a label.  There is no syntax error here because this is very valid C.  We should most likely warn about it though or at least have an option to warn about it.  Confirmed for the warning.
Comment 2 David Malcolm 2016-12-15 21:31:31 UTC
Thanks for filing this bug.

We already issue a warning for this within -Wall, via -Wunused-label (since sometime at or before gcc 4.4, I think):

test.c: In function ‘main’:
test.c:18:3: warning: label ‘case2’ defined but not used [-Wunused-label]
   case2:
   ^~~~~

I think that if the user accidentally omits the space between the "case" and the value, they're unlikely to also have a reference to that label name.

Marking this one as resolved.  Feel free to reopen if I'm missing something here.