public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/102286] New: [constexpr] construct_at incorrectly starts union array lifetime in some cases
@ 2021-09-10 23:24 ldalessandro at gmail dot com
  2021-09-11  0:16 ` [Bug c++/102286] " ldalessandro at gmail dot com
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: ldalessandro at gmail dot com @ 2021-09-10 23:24 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 102286
           Summary: [constexpr] construct_at incorrectly starts union
                    array lifetime in some cases
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ldalessandro at gmail dot com
  Target Milestone: ---

Given the following struct and union,

    struct Foo {
        constexpr explicit Foo(int) {}
    };

    union U {
        Foo data[1];
        constexpr U() {} // no active member
    };

In the function foo() below, assignment to u.data[0] correctly starts the
lifetime of the data array by https://eel.is/c++draft/class.union#general-6.

    constexpr void foo() {
        U u;
        u.data[0] = 0; // okay
    }

However in the function bar() below, &u.data[0] forms a reference before the
start of the lifetime of the data array and thus std::construct_at cannot be
used to start the lifetime of data.

    constexpr void bar() {
        U u;
        std::construct_at(&u.data[0], 0); // forms reference outside lifetime
    }

Currently gcc and msvc accept this invalid code, while clang and icc reject.

See the thread of discussion at
https://lists.isocpp.org/std-proposals/2021/09/3171.php and a live example at
https://godbolt.org/z/Poh6bb5de.

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

end of thread, other threads:[~2023-10-20  3:26 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-10 23:24 [Bug c++/102286] New: [constexpr] construct_at incorrectly starts union array lifetime in some cases ldalessandro at gmail dot com
2021-09-11  0:16 ` [Bug c++/102286] " ldalessandro at gmail dot com
2021-09-11  2:49 ` ldalessandro at gmail dot com
2021-11-17 12:06 ` redi at gcc dot gnu.org
2021-11-17 12:09 ` redi at gcc dot gnu.org
2022-02-18 13:43 ` gcc at ebasoft dot com.pl
2023-10-20  3:26 ` cvs-commit 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).