From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 050FF3857004; Tue, 2 Feb 2021 14:16:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 050FF3857004 From: "markus.kuehni at triviso dot ch" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/98933] New: P0784R7 example support: constexpr new Date: Tue, 02 Feb 2021 14:16:32 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: markus.kuehni at triviso dot ch 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 02 Feb 2021 14:16:33 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D98933 Bug ID: 98933 Summary: P0784R7 example support: constexpr new Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: markus.kuehni at triviso dot ch Target Milestone: --- Trying to recreate the [P0784R7](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p0784r7.h= tml) code example.=20 :13:10: error: 'mark_immutable_if_constexpr' is not a member of 'st= d' 13 | std::mark_immutable_if_constexpr(this->ps); Removed std::mark_immutable_if_constexpr(this->ps); :22:31: error: no matching function for call to 'S::S(const c= har [7])' 22 | constexpr S str("Hello!"); | ^ Added std::add_const::type for constructor argument p.=20 :22:31: in 'constexpr' expansion of 'S("Hello!")' :11:7: error: call to non-'constexpr' function 'void* operator new(std::size_t, void*)' 11 | new(this->ps+k) T{p[k]}; Replaced with std::construct_at() and std::destroy_at() for symmetry, see [91369](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D91369).=20 In file included from /opt/compiler-explorer/gcc-trunk-20210202/include/c++/11.0.0/memory:64, from :1: /opt/compiler-explorer/gcc-trunk-20210202/include/c++/11.0.0/bits/allocator= .h:171:50: error: 'S("Hello!")' is not a constant expression because it refers t= o a result of 'operator new' 171 | return static_cast<_Tp*>(::operator new(__n * sizeof(_Tp)= )); Now I'm stuck.=20 A cleaned-up version is here: https://godbolt.org/z/KWMqna ``` #include #include template struct S : std::allocator { std::size_t sz; T *ps; template=20 constexpr S(typename std::add_const::type (&p)[N]) : sz { N }, ps {this->allocate(N)} { for (std::size_t k =3D 0; ksz; ++k) { std::destroy_at(ps+k); } this->deallocate(this->ps, this->sz); } }; constexpr S str("Hello!"); // str ends up pointing to a static array // containing the string "Hello!". ```=