Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[intro.object] Make the storage in the example for storage providing properly aligned #6422

Merged
merged 2 commits into from
Aug 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion source/basic.tex
Original file line number Diff line number Diff line change
Expand Up @@ -3207,6 +3207,8 @@
\end{note}
\begin{example}
\begin{codeblock}
// assumes that \tcode{sizeof(int)} is equal to 4

template<typename ...T>
struct AlignedUnion {
alignas(T...) unsigned char data[max(sizeof(T)...)];
Expand All @@ -3221,7 +3223,7 @@

frederick-vs-ja marked this conversation as resolved.
Show resolved Hide resolved
struct A { unsigned char a[32]; };
struct B { unsigned char b[16]; };
A a;
alignas(int) A a;
B *b = new (a.a + 8) B; // \tcode{a.a} provides storage for \tcode{*b}
frederick-vs-ja marked this conversation as resolved.
Show resolved Hide resolved
int *p = new (b->b + 4) int; // \tcode{b->b} provides storage for \tcode{*p}
// \tcode{a.a} does not provide storage for \tcode{*p} (directly),
Expand Down