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

            Bug ID: 115178
           Summary: false positive computed goto jump warning
           Product: gcc
           Version: 14.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: foldy at rmki dot kfki.hu
  Target Milestone: ---

> cat test.cc
int test(int i)
{
  int res=0;
  { const void* labels1[2]={&&l1, &&l2};
    goto *labels1[i&1];
    l1: res=1;
    l2: res=2;
  }
  { const void* labels2[2]={&&l3, &&l4};
    goto *labels2[i&1];
    l3: res=3;
    l4: res=4;
  }
  return res;
}

> g++-14 -c test.cc
test.cc: In function ‘int test(int)’:
test.cc:6:5: warning: jump to label ‘l1’
    6 |     l1: res=1;
      |     ^~
test.cc:10:22: note:   as a possible target of computed goto
   10 |     goto *labels2[i&1];
      |                      ^
test.cc:4:17: note:   skips initialization of ‘const void* labels1 [2]’
    4 |   { const void* labels1[2]={&&l1, &&l2};
      |                 ^~~~~~~
test.cc:7:5: warning: jump to label ‘l2’
    7 |     l2: res=2;
      |     ^~
test.cc:10:22: note:   as a possible target of computed goto
   10 |     goto *labels2[i&1];
      |                      ^
test.cc:4:17: note:   skips initialization of ‘const void* labels1 [2]’
    4 |   { const void* labels1[2]={&&l1, &&l2};
      |                 ^~~~~~~


l1/l2 are not possible targets from labels2

Reply via email to