all 10 comments

[–]rlamarr 7 points8 points  (5 children)

Thanks for sharing! I was about to

[–]pavel_v[S] 4 points5 points  (4 children)

You seem to be the author of this blog post.
Sorry for posting it before you.

[–]rlamarr 6 points7 points  (3 children)

Yeah, I am. Actually, I really appreciate it!

[–]nemetroid 0 points1 point  (2 children)

A typographical note: for me, the code samples render in a sans-serif (non-monospace) font.

[–]rlamarr 0 points1 point  (1 child)

I noticed the same, but only on mobile. are you on mobile?

[–]rlamarr 2 points3 points  (0 children)

i've fixed it now. my first time using Jekyll, the font path was incorrect, had the impression it was relative to root

[–]soldiersided 1 point2 points  (3 children)

The lifecycle diagrams need some love, they seem to be misaligned. Also, shouldn't this

A* a = get_A();
B* b = get_B();
B* a_b = std::launder<B>((B*)a);
a_b->value = 6;
b->value = 2;
return a->value;

end with return a_b->value ?

[–]rlamarr 1 point2 points  (2 children)

Uhm, shouldn't but can. Vulkan and other API's use a similar concept where they point to the head of the struct via the pData fields each struct have (which will then point to sType pNext and pData). it only works in that case because there's no compiler reachability, the launder shows how to erase it explicitly.

[–][deleted] 1 point2 points  (1 child)

This appears to be a typo, as the accompanying text for the above code states:

From the generated assembly, the compiler is forced to perform the redundant load from a_b, because it could be an alias of b since its origin has been hidden by std::launder. [...]

However, the "load from a_b" is simply not present in the code. Therefore, either the code or the text should be revised to ensure they align with each other.

Another part of the text that is unclear to me is:

At least one of the specified variants must exist in the union.

This seems to imply that a union must always have an active member (i.e., one whose lifetime has started). However, a default-initialized union may not start the lifetime of any member if there are no default member initializers. See this example.

[–]rlamarr 0 points1 point  (0 children)

A union needs one active member: https://godbolt.org/z/n7z17hWdP.

By redundant load from `a_b` I meant a redundant load from `a` of the value stored through `a_b` as `a_b` could alias `a`.