]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Implement C++26 std::polymorphic [PR119152]
authorJonathan Wakely <jwakely@redhat.com>
Tue, 27 May 2025 09:38:41 +0000 (11:38 +0200)
committerTomasz Kamiński <tkaminsk@redhat.com>
Mon, 2 Jun 2025 11:47:28 +0000 (13:47 +0200)
commita2e1c97205063d7550d9b9c32319715961abd73f
treea9015b58a197d0f6789a5ce92b07d5641ac1902c
parent02a6f9a0df149bbc06e3bbb20be4dde199225296
libstdc++: Implement C++26 std::polymorphic [PR119152]

This patch implements C++26 std::polymorphic as specified in P3019 with
amendment to move assignment from LWG 4251.

The implementation always allocate stored object on the heap. The manager
function (_M_manager) is similary keep with the object (polymorphic::_Obj),
which reduces the size of the polymorphic to size of the single pointer plus
allocator (that is declared with [[no_unique_address]]).

The implementation does not not use small-object optimization (SSO). We may
consider adding this in the future, as SSO is allowed by the standard. However,
storing any polimorphic object will require providing space for two pointers
(manager function and vtable pointer) and user-declared data members.

PR libstdc++/119152

libstdc++-v3/ChangeLog:

* include/bits/indirect.h (std::polymorphic, pmr::polymorphic)
[__glibcxx_polymorphic]: Define.
* include/bits/version.def (polymorphic): Define.
* include/bits/version.h: Regenerate.
* include/std/memory: Define __cpp_lib_polymorphic.
* testsuite/std/memory/polymorphic/copy.cc: New test.
* testsuite/std/memory/polymorphic/copy_alloc.cc: New test.
* testsuite/std/memory/polymorphic/ctor.cc: New test.
* testsuite/std/memory/polymorphic/ctor_poly.cc: New test.
* testsuite/std/memory/polymorphic/incomplete.cc: New test.
* testsuite/std/memory/polymorphic/invalid_neg.cc: New test.
* testsuite/std/memory/polymorphic/move.cc: New test.
* testsuite/std/memory/polymorphic/move_alloc.cc: New test.

Co-authored-by: Tomasz Kamiński <tkaminsk@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
12 files changed:
libstdc++-v3/include/bits/indirect.h
libstdc++-v3/include/bits/version.def
libstdc++-v3/include/bits/version.h
libstdc++-v3/include/std/memory
libstdc++-v3/testsuite/std/memory/polymorphic/copy.cc [new file with mode: 0644]
libstdc++-v3/testsuite/std/memory/polymorphic/copy_alloc.cc [new file with mode: 0644]
libstdc++-v3/testsuite/std/memory/polymorphic/ctor.cc [new file with mode: 0644]
libstdc++-v3/testsuite/std/memory/polymorphic/ctor_poly.cc [new file with mode: 0644]
libstdc++-v3/testsuite/std/memory/polymorphic/incomplete.cc [new file with mode: 0644]
libstdc++-v3/testsuite/std/memory/polymorphic/invalid_neg.cc [new file with mode: 0644]
libstdc++-v3/testsuite/std/memory/polymorphic/move.cc [new file with mode: 0644]
libstdc++-v3/testsuite/std/memory/polymorphic/move_alloc.cc [new file with mode: 0644]