C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Only reason I don't use std::array

From: Sebastian Wittmeier <wittmeier_at_[hidden]>
Date: Thu, 17 Aug 2023 22:06:56 +0200
Optimizers may rely on logic. UB leads to a state called 'Paradoxical Implication' or 'Explosiveness': https://en.wikipedia.org/wiki/Principle_of_explosion   It is summarized as: Ex falso quodlibet. Meaning UB can lead to *any* effect. Even if the creators of the optimizer did not knowingly intend to take advantage of it or punish a programmer for it.   Example: Imagine a new optimizer version uses heuristics or language model to improve the intermediate representation of the compiled code. With each compilation run, different candidates of parts of the program are generated and logically tested for correctness. As your program is relying on UB, the logical test could possibly result in a passing result, although the generated program totally malfunctions.   To prevent this kind of result, the programmers of the optimizer would have to specify your specific use of UB in the way your are misusing it.   As far as the compiler implementations are not specifying those situations, I would rather not rely on that they put those cases as valid in their logical tests. Especially because more often than not, there are reasons, why the standard chose UB in particular situations. And next standard versions could specify the behavior in a different way than you assume now.   -----Ursprüngliche Nachricht----- Von:Frederick Virchanza Gotham via Std-Proposals <std-proposals_at_[hidden]> Gesendet:Do 17.08.2023 21:38 Betreff:Re: [std-proposals] Only reason I don‘t use std::array An:std-proposals <std-proposals_at_[hidden]>; CC:Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>; On Thu, Aug 17, 2023 at 7:39 PM Tom Honermann <tom_at_[hidden]> wrote: > > I agree. Optimizers are not written to take advantage of UB. They are > written in accordance with what the standard specifies as defined > behavior. When code fails to adhere to what the standard specifies, then > optimizers might behave in unexpected ways because a property they rely > on (such as the existence of an object of a certain type) has been violated. There is no invalid bit pattern for an array of int's. Maybe an array of float's could have an invalid bit pattern. I mean the 'existence of an object' will come down to 0's and 1's at the end of it all. -- Std-Proposals mailing list Std-Proposals_at_[hidden] https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2023-08-17 20:06:58