[llvm-bugs] [Bug 48453] New: Assigning to non-active trivial union member is not accepted in constexpr context

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Dec 9 03:34:26 PST 2020


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: unassignedclangbugs at nondot.org
          Reporter: m.cencora at gmail.com
                CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
                    llvm-bugs at lists.llvm.org, richard-llvm at 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20201209/587c0574/attachment.html>


More information about the llvm-bugs mailing list