On Wed, Apr 03, 2024 at 12:58:12PM -0400, Jason Merrill wrote:
> On 4/3/24 12:42, Jakub Jelinek wrote:
> > On Wed, Apr 03, 2024 at 12:07:48PM -0400, Jason Merrill wrote:
> > > Using std::is_constant_evaluated directly in a loop condition is, as the
> > > paper says, unlikely and "horrendous code", so I'm not concerned about
> > > surprising effects, though I guess we should check for it with
> > > maybe_warn_for_constant_evaluated.
> > 
> > Ok, though guess the question is what to say about it.
> > Because unlike the existing cases in maybe_warn_for_constant_evaluated
> > where it always evaluates to true or always to false depending on where,
> > in the trivial empty iteration statements it evaluates to always true or
> > always false depending or sometimes true, sometimes false, depending on
> > if the condition is a constant expression that evaluates to true (then it is
> > always true), or if in immediate function (also always true), or if not
> > in constexpr function (then always false), or in constexpr function (then
> > it might be true or false).
> > Not sure how exactly to word that.
> > Maybe just say that it is horrendous code to use std::is_constant_evaluated
> > () in trivial empty iteration statement conditions ;)
> 
> Maybe if the condition constant-evaluates to true, warn something like
> "%<std::is_constant_evaluated%> always constant-evaluates to true in the
> condition of a trivially empty iteration statement"?

Given the mails on core about this, isn't it actually the case that not all
"trivial infinite loops" actually loop at all or if they loop, don't loop
infinitely?
I.e. what I wrote in the patch would be wrong and that generally we need to
use ANNOTATE_EXPR in some cases?
As in, for trivially empty iteration statements try to evaluate the
maybe_const_value evaluate condition with mce_true, if it yields true,
try to maybe_const_value evaluate condition with mce_false, if it also
yields true, replace it with true, but if the former returns true and
the latter isn't a constant expression or returns false mark the loop with
ANNOTATE_EXPR as infinite loop regardless of -ffinite-loops and actually
keep invoking the condition in there?

        Jakub

Reply via email to