Is it defined behavior to reference an early member from a later member expression during aggregate initialization?

Your second case is undefined behavior, you are no longer using aggregate initialization, it is still list initialization but in this case you have a user defined constructor which is being called. In order to pass the second argument to your constructor it needs to evaluate foo.i but it is not initialized yet since you … Read more

Implementing a std::vector like container without undefined behavior

This is topic that is under active discussion, we can see this in the proposal p0593: Implicit creation of objects for low-level object manipulation. This is a pretty solid discussion of the issues and why they are not fixable without changes. If you have different approaches or strong views on the approaches being considered you … Read more

At what point does dereferencing the null pointer become undefined behavior?

I think the second opus of What every C programmer should know about Undefined Behavior might help illustrate this issue. Taking the example of the blog: void contains_null_check(int *P) { int dead = *P; if (P == 0) return; *P = 4; } Might be optimized to (RNCE: Redundant Null Check Elimintation): void contains_null_check_after_RNCE(int *P) … Read more

Is infinite loop still undefined behavior in C++ if it calls shared library?

There are a number of places where the language of the Standard gives compilers freedoms beyond what are required for useful optimizations, but which would instead provide compilers with ways to throw the Principle of Least Astonishment out the window. The way the rules about endless loops are written fits that category. Most of the … Read more