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/51896] New: Should gcc warn if a variable initializer inside a switch statement is never used?


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

             Bug #: 51896
           Summary: Should gcc warn if a variable initializer inside a
                    switch statement is never used?
    Classification: Unclassified
           Product: gcc
           Version: 4.6.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: kaie@kuix.de


While maintaining existing code, we encountered a snippet like this:

--------------- begin test.c -----------------------
#include "stdio.h"
#include "stdlib.h"

int main(int argc, char *argv[])
{
  int *a = (int*)0xaaaaaaaa;
  printf("a is: %p\n", a);

  int r = rand() % 2;

  switch (r)
  {
    int *b = (int*)0xbbbbbbbb;

    case 2: break;
    default:
      printf("b is: %p\n", b);
  }

  return 0;
} 
--------------- end test.c -----------------------

$ gcc -o test -Wall test.c
test.c: In function âmainâ:
test.c:17:13: warning: âbâ may be used uninitialized in this function
[-Wuninitialized]

$ ./test 
a is: 0xaaaaaaaa
b is: 0x434b5fc4


Proposal: 

As gcc decides to ignore value 0xbbbbbbbb, it should print a warning message,
informing the user, e.g.:

  test.c: warning: ignoring initialization value â0xbbbbbbbbâ


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