[Bug c/78285] New: error on duplicate switch label where a note should be

msebor at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Nov 10 00:09:00 GMT 2016


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78285

            Bug ID: 78285
           Summary: error on duplicate switch label where a note should be
           Product: gcc
           Version: 7.0
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

GCC normally issues a single error or warning message for a constraint
violation that is then sometimes followed by a note with additional context. 
In the case of an error for a duplicated case label in a switch statement,
however, GCC issues at least two errors: one for each of duplicates and one for
the original.  The test case below shows this inconsistency.  The duplicate
label error should be changed into a not for consistency.

$ cat z.c && gcc -S -Wall -Wextra z.c
void f (void)
{
  switch (0) {
  case 0: ;
  case 0: ;
  case 0: ;
  }
}

void f (int);
z.c: In function ‘f’:
z.c:5:3: error: duplicate case value
   case 0: ;
   ^~~~
z.c:4:3: error: previously used here
   case 0: ;
   ^~~~
z.c:6:3: error: duplicate case value
   case 0: ;
   ^~~~
z.c:4:3: error: previously used here
   case 0: ;
   ^~~~
z.c: At top level:
z.c:10:6: error: conflicting types for ‘f’
 void f (int);
      ^
z.c:1:6: note: previous definition of ‘f’ was here
 void f (void)
      ^


More information about the Gcc-bugs mailing list