2019-01-11 Jonathan Wakely <jwakely@redhat.com>
+ * 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.
+
* include/std/chrono (duration_values::zero(), duration_values::min())
(duration_values::max()): Add noexcept.
(duration::zero(), duration::min(), duration::max()): Likewise.
: _Weak_result_type_memfun<typename remove_cv<_Functor>::type>
{ };
+#if __cplusplus <= 201703L
// Detect nested argument_type.
template<typename _Tp, typename = __void_t<>>
struct _Refwrap_base_arg1
{
using result_type = typename _Mem_fn_traits<_MemFunPtr>::__result_type;
};
+#endif // ! C++20
/**
* @brief Primary class template for reference_wrapper.
*/
template<typename _Tp>
class reference_wrapper
+#if __cplusplus <= 201703L
+ // In C++20 std::reference_wrapper<T> allows T to be incomplete,
+ // so checking for nested types could result in ODR violations.
: public _Reference_wrapper_base_memfun<typename remove_cv<_Tp>::type>
+#endif
{
_Tp* _M_data;
typename result_of<_Tp&(_Args&&...)>::type
operator()(_Args&&... __args) const
{
+#if __cplusplus > 201703L
+ static_assert(sizeof(type), "type must be complete");
+#endif
return std::__invoke(get(), std::forward<_Args>(__args)...);
}
};
--- /dev/null
+// Copyright (C) 2019 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+// P0357R3 reference_wrapper for incomplete types
+
+#include <functional>
+
+struct Incomplete;
+
+template class std::reference_wrapper<Incomplete>;
+
+Incomplete& f();
+
+std::reference_wrapper<Incomplete> r = f();
+static_assert( std::is_same_v<decltype(r)::type, Incomplete> );
+static_assert( std::is_same_v<decltype(r.get()), Incomplete&> );
+
+std::reference_wrapper r2 = f();
+static_assert( std::is_same_v<decltype(r), decltype(r2)> );