public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/98637] New: Changing active union member via assignment expression should require trivial default constructor in constexpr context
@ 2021-01-12 11:22 m.cencora at gmail dot com
  2021-08-28  0:15 ` [Bug c++/98637] " pinskia at gcc dot gnu.org
  2023-12-12 18:45 ` ppalka at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: m.cencora at gmail dot com @ 2021-01-12 11:22 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98637

            Bug ID: 98637
           Summary: Changing active union member via assignment expression
                    should require trivial default constructor in
                    constexpr context
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: m.cencora at gmail dot com
  Target Milestone: ---

According to http://eel.is/c++draft/class.union#general-6 following code should
be rejected
because changing of active union member via assignment expression should be
allowed only for classes with non-deleted trivial default constructor.

This is per Richard Smith's comment in
https://bugs.llvm.org/show_bug.cgi?id=48453

g++ -std=c++20

#include <memory>

struct NonTrivial
{
    constexpr NonTrivial() : b(true) {}

    bool b;
};

union Un
{
    bool f1;
    NonTrivial f2;
};

constexpr bool test()
{
    Un un{ .f1 = false };
    un.f2 = {}; // should be an error here, and require
std::construct_at(&un.f2);
    return un.f2.b;
}

static_assert(test());

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-12-12 18:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-12 11:22 [Bug c++/98637] New: Changing active union member via assignment expression should require trivial default constructor in constexpr context m.cencora at gmail dot com
2021-08-28  0:15 ` [Bug c++/98637] " pinskia at gcc dot gnu.org
2023-12-12 18:45 ` ppalka at gcc dot gnu.org

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).