upvote
Architecture dependent is not the same as undefined.
reply
Also, the spec says it’s undefined. But compiler authors can always special-case their own compilers.
reply
Clang/LLVM at least treats this as UB, not as implementation defined behaviour however according to an LLVM dev
reply
Undefined behavior is not the same as implementation-defined or unspecified behavior. A program with undefined behavior is by definition an incorrect program. But there are cases where the spec actually gives some margin to the implementation. Programs relying on the choices of the implementation may be correct, even if non-portable.
reply
>A program with undefined behavior is by definition an incorrect program.

This is simply false and an oft repeated myth. Undefined behavior has a specific technical definition that is in the C++ standard [1] and there is absolutely no mention in that definition or the implication of that definition that undefined behavior necessarily results in an invalid or incorrect program.

The definition of undefined behavior, right from the standard itself is... and I quote... get ready for it...

"behavior for which this document imposes no requirements"

That's it, nothing more, nothing less.

The standard even goes out of its way to state the following:

"Permissible undefined behavior ranges from ignoring the situation completely with unpredictable results, *to behaving during translation or program execution in a documented manner* characteristic of the environment".

Behaving in a documented manner characteristic of an environment is a far cry from being by incorrect by definition.

[1] https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/n49...

reply
>This document imposes no requirements on the behavior of programs that contain undefined behavior

That's saying that programs that exhibit undefined behaviour are not governed by the C++ spec. For a program to be a valid, spec governed piece of C++ code it has to exhibit no undefined behaviour (outside of some constraints). Its accurate to say that any undefined behaviour results in the code being executed no longer being C++, and it can have any behaviour. That's synonymous in common developer speak with 'incorrect', as its desirable for your C++ code to be executed as C++

reply
Do I love selective quoting! "Undefined behavior may be expected... when a program uses an incorrect construct or invalid data". There is also "erroneous behaviour" which "is always the consequence of incorrect program code".

Honestly, you'd have a better argument by quoting that "Correct execution" can include undefined behavior and erroneous behavior, depending on the data being processed". Which is quite a wild sentence to read, but here we are.

reply
I appreciate the correction. Although it should be said that modern implementations tend to opt to assume that UB never happens.
reply