This program fails to compile on MSVC. Why is this? Is this an intentional design choice or a bug?

#define NO_UNIQUE_ADDRESS [[no_unique_address]] [[msvc::no_unique_address]] struct S1 { struct {} e NO_UNIQUE_ADDRESS; }; struct S2 : S1 { struct {} e NO_UNIQUE_ADDRESS; }; struct S3 : S2 { struct {} e NO_UNIQUE_ADDRESS; }; int main() { static_assert(sizeof(S3) == sizeof(S1)); }

user541686's user avatar

2

the compiler may optimize it to occupy no space - "may" is not a requirement.

2026-01-26 04:33:59 +00:00

Commented 2 hours ago

This is MSVC, we can be fairly sure this is a bug.

2026-01-26 06:45:54 +00:00

Commented 14 mins ago

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.