]> git.ipfire.org Git - thirdparty/gcc.git/commit
P0357R3 reference_wrapper for incomplete types
authorredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 11 Jan 2019 23:41:11 +0000 (23:41 +0000)
committerredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 11 Jan 2019 23:41:11 +0000 (23:41 +0000)
commitf5480b8c1e514d5942e8650c4497b44641f59390
tree110481d49087c9adfb538e4018d5c8dd8e514526
parent36496c4da54f144822e1675fbea09925e86af779
P0357R3 reference_wrapper for incomplete types

This patch implements the C++2a proposal to allow incomplete types in
std::reference_wrapper, which was previously undefined.

The change cannot be implemented for earlier standards, because prior to
C++2a std::reference_wrapper has a weak result type, so must inspect the
template argument to see if it defines a nested result_type member. That
is deprecated (but still required) in C++17, and removed from C++2a.

The removal of the base class from reference_wrapper is a potential ABI
change, as it could alter the layout of a type which derives from
reference_wrapper<T> and from an empty type with _Weak_result_type<T> as
a base class.  Previously the repeated _Weak_result_type<T> base class
would have prevented the empty base-class optimization, but if
reference_wrapper<T> no longer derives from it, the empty class could be
placed at the same address as the reference_wrapper<T> base.  In
practice, the only types which derive from _Weak_result_type or from
_Reference_wrapper_base_memfun or any of its base classes are non-empty
types defined in libstdc++: std::reference_wrapper, std::function, and
std::_Bind. As they are non-empty types, they are not eligible for EBO
anyway.

* include/bits/refwrap.h [__cplusplus > 201703L]
(_Refwrap_base_arg1, _Refwrap_base_arg2, _Reference_wrapper_base)
(_Reference_wrapper_base_memfun): Do not define for C++2a.
(reference_wrapper): Do not derive from _Reference_wrapper_base_memfun
for C++2a.
(reference_wrapper::operator()): Add static assertion.
* testsuite/20_util/reference_wrapper/incomplete.cc: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@267866 138bc75d-0d04-0410-961f-82ee72b054a4
libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/refwrap.h
libstdc++-v3/testsuite/20_util/reference_wrapper/incomplete.cc [new file with mode: 0644]