← Back to context

Comment by saagarjha

7 hours ago

Sure it can. That code path has unconditional UB and thus it is not valid.

Only if there would be no side-effects. Which there are.

  • No this is irrelevant for making this decision

    • I've mentioned elsewhere the standards, and compilers as well, disagreeing with you here.

      But feel free to run against the various compilers through godbolt. [0] They won't optimise the branch away. Access to a volatile, must be preserved, in the order that they exist. No optimisation, UB or otherwise, is allowed to impede that. Because an access is a side-effect.

      [0] https://godbolt.org/z/85cGhq3Ta

      4 replies →

  • This looks like a long back and fourth, that can easily be solved by a minute or two on godbolt...

    • > that can easily be solved by a minute or two on godbolt...

      Unfortunately it's not that simple when it comes to UB. If the snippet in question does in fact exhibit UB then there's no guarantee whatever Godbolt shows will generalize to other programs/versions/compilers/environments/etc.

      5 replies →