[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gcc-bugs
Subject:    [Bug c++/86767] New: continue statements in constexpr functions causes unbounded looping
From:       "syang0 at cs dot stanford.edu" <gcc-bugzilla () gcc ! gnu ! org>
Date:       2018-07-31 22:02:33
Message-ID: bug-86767-4 () http ! gcc ! gnu ! org/bugzilla/
[Download RAW message or body]

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

            Bug ID: 86767
           Summary: continue statements in constexpr functions causes
                    unbounded looping
           Product: gcc
           Version: 8.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: syang0 at cs dot stanford.edu
  Target Milestone: ---

Created attachment 44476
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=44476&action=edit
main.cc

The constexpr function below fails to evaluate at compile-time and causes
unbounded looping on the inner for-loop, despite it having a very well defined
bound [0, 10).

The cause seems to be related to the "continue" statement in the outer for loop
of the constexpr function. If I remove the "continue" completely, the code
compiles fine. If I remove the constexpr requirement for "num" variable in
main() (which stores the return value), it compiles and runs fine without
hanging.

This problem reproduces in g++ versions 8.2, 8.1, 7.3, 7.2, 7.1, 6.3, and 5.5
and was compiled with the command 'g++ --std=c++17 main.cc'


constexpr int
sampleFn()
{
    for (int i = 0; i < 10; ++i) {
        continue;

        // Should never run and is well bounded, but compiler hangs here
        for (int j = 0; j < 10; ++j ) {}
    }

    return 10;
}

void test()
{
    // Removing 'constexpr' allows compilation to proceed
    constexpr int num = sampleFn();
}=
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic