C++ Logo

std-discussion

Advanced search

Re: Is forward progress guarantee still useful?

From: Nate Eldredge <nate_at_[hidden]>
Date: Wed, 17 Sep 2025 05:39:44 +0000
On Sep 16, 2025, at 20:11, Yongwei Wu via Std-Discussion <std-discussion_at_[hidden]> wrote:
>
> I am wondering what are the real-world benefits of the forward progress guarantee today.... They probably existed, but are they still there? (If not, should we ...?)

I thought the canonical example was something like https://godbolt.org/z/G6onne47x:

[[gnu::pure]] int update(int) ; // opaque but known to have no side effects

void foo(void) {
    int r = 1;
    while (r != 0) {
        r = update(r);
    }
    // no further use of r
}

Instead of an opaque pure function, you may imagine replacing `update` with a sufficiently complicated expression having no side effects, such that the compiler cannot reasonably determine if it will return 0 within finitely many iterations.

With the "forward progress guarantee" (I assume you refer to https://eel.is/c++draft/intro.progress#1) the compiler can and will delete the loop as dead code, and optimize `foo()` into just a `ret`. Without it (use `-fno-finite-loops`), the compiler must emit code to actually execute all iterations of the loop, since if it turns out the loop does not terminate, the function `foo()` must never return.

Such examples, where we have complicated code to compute a value that is not used, must be very common in auto-generated code, and people rely heavily on compilers to optimize it out.



Received on 2025-09-17 05:39:48