C++ Logo

std-proposals

Advanced search

Re: [std-proposals] P2809R0 Infinite loops

From: Barry Revzin <barry.revzin_at_[hidden]>
Date: Tue, 4 Apr 2023 11:12:02 -0500
On Tue, Apr 4, 2023, 10:59 AM Marcin Jaczewski via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> I wonder why not make infinite loops simply explicit?
> Like:
>
> ```
> while (std::infiniti) { }
> ```
>
> Now it will be clear to the reader and compiler that we expect it to
> be infinite.
> Reading `std::infiniti` would be considered an observable behavior or
> something
> like that.
>
> Alternative add attribute to signal to everyone that this loop should not
> break.
> We could even reuse attribute:
>
> ```
> [[noreturn]] while(true) {}
> ```
>
> This would have benefits that compilers could more aggressively warn
> if they see a loop that can't break and therefore create UB.
>

Because the goal is to make all the existing infinite loops non-UB, rather
than add some new construct that people would have to go and update all
their [not actually broken] code to.

Barry

>

Received on 2023-04-04 16:12:15