From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 2BB003858D1E; Wed, 17 May 2023 13:50:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2BB003858D1E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1684331423; bh=mvdtUobkC+M6vP4ToYTpc4T2yLiU1YQHpCUMpXyVaAQ=; h=From:To:Subject:Date:From; b=L4J+nB5stHPaeda3xTanQlR3oQW0OmYL3Fy473lO1bkXqZ96tClnyQwAzHCtElS/y DaE4Q0odtcdMfyeaCrgZ00BB/fd4Uq+VH0ecxVouarGuSf7scojC2vQHD2W8iwj0+l mUnMimWB9QrBxqz7NxxOt5kEScBeAYUdpEIdGa3Y= From: "barry.revzin at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/109890] New: vector's constructor doesn't start object lifetimes during constant evaluation Date: Wed, 17 May 2023 13:50:22 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: barry.revzin at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D109890 Bug ID: 109890 Summary: vector's constructor doesn't start object lifetimes during constant evaluation Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: barry.revzin at gmail dot com Target Milestone: --- >From StackOverflow (https://stackoverflow.com/q/76269606/2069064), clang rejects this code when compiling with libstdc++: #include consteval auto bar(int n){ std::vector v(n); return v[0]; } constexpr auto m =3D bar(5); This is because libstdc++ basically does something like this: #include class V { int* p; int n; std::allocator alloc; public: constexpr V(int n) : n(n) { p =3D alloc.allocate(n); // fill with 0s? for (int i =3D 0; i !=3D n; ++i) { p[i] =3D 0; } } constexpr ~V() { alloc.deallocate(p, n); } }; consteval auto bar(int n) { V v(n); return n; } static_assert(bar(5) =3D=3D 5); And clang is more picky about the assignment there - it doesn't like just writing p[0] =3D 0, because the int's lifetime hasn't started yet. gcc acce= pts the above though.=20 I think that's... technically correct (if pedantic) and libstdc++'s path ne= eds to do a construct_at somewhere.=