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

            Bug ID: 85159
           Summary: if constexpr error about goto
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: drepper.fsp+rhbz at gmail dot com
  Target Milestone: ---

This is actually something I deliberate used if constexpr for to avoid warnings
but gcc creates a new kind of error.  Take this silly code:

template<bool B>
int foo(int a, int b)
{
  if constexpr (B) {
    a += 1;
    goto L;
  } else
    b += 1;
  if constexpr (B) {
  L:
    return a - b;
  } else
    return b - a;
}

int main()
{
  return foo<false>(3, 4);
}

The definition and use of the label are in if constexpr blocks controlled by
the same condition.  gcc issues this warning (this is mainline gcc as of last
week or so):

u.cc: In function ‘int foo(int, int)’:
u.cc:10:3: error: jump to label ‘L’
   L:
   ^
u.cc:6:10: note:   from here
     goto L;
          ^
u.cc:9:16: note:   enters constexpr if statement
   if constexpr (B) {
                ^


I think gcc should look at the block conditions and avoid the error.

Reply via email to