https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85599
Thomas Koenig <tkoenig at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords|wrong-code |diagnostic
Status|UNCONFIRMED |NEW
Last reconfirmed| |2018-05-02
CC| |tkoenig at gcc dot gnu.org
Ever confirmed|0 |1
Severity|normal |enhancement
--- Comment #2 from Thomas Koenig <tkoenig at gcc dot gnu.org> ---
(In reply to kargl from comment #1)
> 10.1.5.4.2 Evaluation of logical intrinsic operations
>
> Once the interpretation of a logical intrinsic operation is
> established, the processor may evaluate any other expression
> that is logically equivalent, provided that the integrity of
> parentheses in any expression is not violated.
>
> Two expressions of type logical are logically equivalent
> if their values are equal for all possible values of their
> primaries.
>
> With 'flag = .false.', gfortran can determine that
> check()'s return value is irrelevant. So, the
> the values of 'flag .and. check()' and 'flag' are
> logically equivalent.
>
> Note, 'check() .and. flag' is logically equivalent
> to 'flag', but the standard does not require any order
> in the evaluation of op1 and op2 in a binary operation.
>
> Also, note that this is my interpretation. I could
> be wrong.
You're right, the code relying on side effects is undefined.
Confirming as enhancement request.
Would be nice to add a warning to catch this, though.