C++ Logo

STD-PROPOSALS

Advanced search

Subject: Re: [std-proposals] Remove infinite loop UB
From: Ville Voutilainen (ville.voutilainen_at_[hidden])
Date: 2020-06-01 13:30:52


On Mon, 1 Jun 2020 at 20:58, connor horman via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> I have something to add.
> Consider a C++ program with that requires a constant expression which contains a non-trivial loop (one that cannot be analyzed easily, or at all, possibly because whether or not it terminates depends on the same analysis that the compiler performs, which is itself possible to write ).
> If the loop terminates, its a core constant expression. If it does not, it isn't a core constant expression, because it contains core language undefined behaviour.
> It would be impossible for the compiler to determine over all potential constant expressions which are and aren't a constant expression based on these rules. Such a check would be uncomputable, see https://en.wikipedia.org/wiki/Halting_problem.
> This means that, in the presence of infinite loops being UB, there exist strictly conforming C++ programs which cannot be correctly compiled by any implementation, for the same reason that no algorithm exists for the halting problem (under the assumption the compiler for all C++ implementations are running on something which is as good as a turing machine).

For a constant expression, the compiler doesn't need to determine
whether it will halt. At some point, the evaluation
will exceed an implementation resource limit, and the compiler will
just give up. And as far as I understand what the
standard says, the compiler isn't required to abort constexpr
evaluation and deem the function a run-time function;
it can give a hard error instead.

A Turing Machine's tape is infinite. The tape of your compiler is not.
So yes, there are strictly conforming C++ programs
that cannot be correctly compiled.

I fail to see what impact that should have on infinite loops being UB.


STD-PROPOSALS list run by std-proposals-owner@lists.isocpp.org

Standard Proposals Archives on Google Groups