https://bugs.llvm.org/show_bug.cgi?id=48453
Bug ID: 48453
Summary: Assigning to non-active trivial union member is not
accepted in constexpr context
Product: clang
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: C++2a
Assignee: unassignedclangb...@nondot.org
Reporter: m.cenc...@gmail.com
CC: blitzrak...@gmail.com, erik.pilking...@gmail.com,
llvm-bugs@lists.llvm.org, richard-l...@metafoo.co.uk
Following program fails to compile in C++20 mode.
gcc accepts this code without any workarounds.
Even if following expression 'un.f2.f2 = true;' does not implicitly initialize
un.f2 (which I think it should according to language rules), then WORKAROUND1
should fix it, but it still doesn't work.
Passing -DWORKAROUND2 is needed to make this compile on clang.
#include <memory>
union Un
{
constexpr Un() {}
char f1;
union NestedUn
{
constexpr NestedUn() {}
int f1;
bool f2;
} f2;
};
constexpr bool test()
{
Un un;
#ifdef WORKAROUND1
un.f2 = {};
#elif WORKAROUND2
std::construct_at(&un.f2);
#endif
un.f2.f2 = true;
return un.f2.f2;
}
static_assert(test());
--
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs