Author: marshall Date: Mon Nov 27 07:51:36 2017 New Revision: 319038 URL: http://llvm.org/viewvc/llvm-project?rev=319038&view=rev Log: Implement LWG#2948: unique_ptr does not define operator<< for stream output
Added: libcxx/trunk/test/std/utilities/memory/unique.ptr/unique.ptr.special/io.fail.cpp libcxx/trunk/test/std/utilities/memory/unique.ptr/unique.ptr.special/io.pass.cpp Modified: libcxx/trunk/include/memory libcxx/trunk/include/ostream libcxx/trunk/www/cxx2a_status.html Modified: libcxx/trunk/include/memory URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/memory?rev=319038&r1=319037&r2=319038&view=diff ============================================================================== --- libcxx/trunk/include/memory (original) +++ libcxx/trunk/include/memory Mon Nov 27 07:51:36 2017 @@ -387,6 +387,9 @@ template<class T, class... Args> unique_ template<class T> unique_ptr<T> make_unique(size_t n); // C++14 template<class T, class... Args> unspecified make_unique(Args&&...) = delete; // C++14, T == U[N] +template<class E, class T, class Y, class D> + basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, unique_ptr<Y, D> const& p); + template<class T> class shared_ptr { Modified: libcxx/trunk/include/ostream URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/ostream?rev=319038&r1=319037&r2=319038&view=diff ============================================================================== --- libcxx/trunk/include/ostream (original) +++ libcxx/trunk/include/ostream Mon Nov 27 07:51:36 2017 @@ -1071,6 +1071,18 @@ operator<<(basic_ostream<_CharT, _Traits return __os << __p.get(); } +template<class _CharT, class _Traits, class _Yp, class _Dp> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_same<void, typename __void_t<decltype(declval<basic_ostream<_CharT, _Traits>&>() << declval<_Yp>())>::type>::value, + basic_ostream<_CharT, _Traits>& +>::type +operator<<(basic_ostream<_CharT, _Traits>& __os, unique_ptr<_Yp, _Dp> const& __p) +{ + return __os << __p.get(); +} + template <class _CharT, class _Traits, size_t _Size> basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x) Added: libcxx/trunk/test/std/utilities/memory/unique.ptr/unique.ptr.special/io.fail.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/memory/unique.ptr/unique.ptr.special/io.fail.cpp?rev=319038&view=auto ============================================================================== --- libcxx/trunk/test/std/utilities/memory/unique.ptr/unique.ptr.special/io.fail.cpp (added) +++ libcxx/trunk/test/std/utilities/memory/unique.ptr/unique.ptr.special/io.fail.cpp Mon Nov 27 07:51:36 2017 @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// template<class CharT, class Traits, class Y, class D> +// basic_ostream<CharT, Traits>& +// operator<<(basic_ostream<CharT, Traits>& os, const unique_ptr<Y, D>& p); + +// -?- Remarks: This function shall not participate in overload resolution unless os << p.get() is a valid expression. + +#include <memory> +#include <sstream> +#include <cassert> + +class A {}; + +int main() +{ + std::unique_ptr<A> p(new A); + std::ostringstream os; + os << p; +} Added: libcxx/trunk/test/std/utilities/memory/unique.ptr/unique.ptr.special/io.pass.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/memory/unique.ptr/unique.ptr.special/io.pass.cpp?rev=319038&view=auto ============================================================================== --- libcxx/trunk/test/std/utilities/memory/unique.ptr/unique.ptr.special/io.pass.cpp (added) +++ libcxx/trunk/test/std/utilities/memory/unique.ptr/unique.ptr.special/io.pass.cpp Mon Nov 27 07:51:36 2017 @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// template<class CharT, class Traits, class Y, class D> +// basic_ostream<CharT, Traits>& +// operator<<(basic_ostream<CharT, Traits>& os, const unique_ptr<Y, D>& p); + +#include <memory> +#include <sstream> +#include <cassert> + +int main() +{ + std::unique_ptr<int> p(new int(3)); + std::ostringstream os; + assert(os.str().empty()); + os << p; + assert(!os.str().empty()); +} Modified: libcxx/trunk/www/cxx2a_status.html URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/www/cxx2a_status.html?rev=319038&r1=319037&r2=319038&view=diff ============================================================================== --- libcxx/trunk/www/cxx2a_status.html (original) +++ libcxx/trunk/www/cxx2a_status.html Mon Nov 27 07:51:36 2017 @@ -65,7 +65,7 @@ <tr><td><a href="https://wg21.link/P0439R0">P0439R0</a></td><td>LWG</td><td>Make <tt>std::memory_order</tt> a scoped enumeration</td><td>Albuquerque</td><td></td><td></td></tr> <tr><td><a href="https://wg21.link/P0457R2">P0457R2</a></td><td>LWG</td><td>String Prefix and Suffix Checking</td><td>Albuquerque</td><td></td><td></td></tr> <tr><td><a href="https://wg21.link/P0550R2">P0550R2</a></td><td>LWG</td><td>Transformation Trait <tt>remove_cvref</tt></td><td>Albuquerque</td><td>Complete</td><td>6.0</td></tr> - <tr><td><a href="https://wg21.link/P0600R1">P0600R1</a></td><td>LWG</td><td>nodiscard in the Library</td><td>Albuquerque</td><td></td><td></td></tr> + <tr><td><a href="https://wg21.link/P0600R1">P0600R1</a></td><td>LWG</td><td>nodiscard in the Library</td><td>Albuquerque</td><td><I>In Progress</I></td><td></td></tr> <tr><td><a href="https://wg21.link/P0616R0">P0616R0</a></td><td>LWG</td><td>de-pessimize legacy <numeric> algorithms with std::move</td><td>Albuquerque</td><td></td><td></td></tr> <tr><td><a href="https://wg21.link/P0653R2">P0653R2</a></td><td>LWG</td><td>Utility to convert a pointer to a raw pointer</td><td>Albuquerque</td><td>Complete</td><td>6.0</td></tr> <tr><td><a href="https://wg21.link/P0718R2">P0718R2</a></td><td>LWG</td><td>Atomic shared_ptr</td><td>Albuquerque</td><td></td><td></td></tr> @@ -106,7 +106,7 @@ <tr><td><a href="https://wg21.link/LWG2941">2941</a></td><td>[thread.req.timing] wording should apply to both member and namespace-level functions</td><td>Albuquerque</td><td><i>Nothing to do</i></td></tr> <tr><td><a href="https://wg21.link/LWG2944">2944</a></td><td>LWG 2905 accidentally removed requirement that construction of the deleter doesn't throw an exception</td><td>Albuquerque</td><td><i>Nothing to do</i></td></tr> <tr><td><a href="https://wg21.link/LWG2945">2945</a></td><td>Order of template parameters in optional comparisons</td><td>Albuquerque</td><td>Complete</td></tr> - <tr><td><a href="https://wg21.link/LWG2948">2948</a></td><td>unique_ptr does not define operator<< for stream output</td><td>Albuquerque</td><td></td></tr> + <tr><td><a href="https://wg21.link/LWG2948">2948</a></td><td>unique_ptr does not define operator<< for stream output</td><td>Albuquerque</td><td>Complete</td></tr> <tr><td><a href="https://wg21.link/LWG2950">2950</a></td><td>std::byte operations are misspecified</td><td>Albuquerque</td><td>Complete</td></tr> <tr><td><a href="https://wg21.link/LWG2952">2952</a></td><td>iterator_traits should work for pointers to cv T</td><td>Albuquerque</td><td>Complete</td></tr> <tr><td><a href="https://wg21.link/LWG2953">2953</a></td><td>LWG 2853 should apply to deque::erase too</td><td>Albuquerque</td><td></td></tr> _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits