From: Wilhelm Meier <wilhelm.meier@hs-kl.de>
To: <gcc-help@gcc.gnu.org>
Subject: Re: Unions, common-initial subsequence and UB
Date: Thu, 20 Oct 2022 15:10:58 +0200 [thread overview]
Message-ID: <eef96e78-3c73-b1ad-e130-b791b44e19c7@hs-kl.de> (raw)
In-Reply-To: <8dc1aaa8-fe1b-e11b-b5e4-ae1acc30ff02@hs-kl.de>
On 20.10.22 13:46, Wilhelm Meier wrote:
> Hi all,
>
> this is more a general question instead of a g++ specific one:
>
> the standard explicitly makes this exception: accessing an inactive
> union member is not UB if the members are structs with initial common
> sequence.
>
> Is this also true in a constexpr context? I ask this because the chapter
> for constexpr expression does not mention this exception accessing an
> inactive memeber.
Here is some test-code:
struct A {
char e0;
};
struct B {
char e0;
};
template<typename A, typename B>
union U {
A a;
B b;
};
int main() {
constexpr U<A, B> u{.a = {1}}; // sets member a to active
constexpr char t1 = u.b.e0; // should be ok, because read via a
struct with common initial sequence
}
prev parent reply other threads:[~2022-10-20 13:11 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-20 11:46 Wilhelm Meier
2022-10-20 13:10 ` Wilhelm Meier [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=eef96e78-3c73-b1ad-e130-b791b44e19c7@hs-kl.de \
--to=wilhelm.meier@hs-kl.de \
--cc=gcc-help@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).