From: Igor Zhukov Date: Tue, 2 Aug 2022 10:46:31 +0000 (+0200) Subject: [libc++] Implement P2499R0 (`string_view` range constructor should be `explicit`) X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8be1197285bdff6e03bf26b77052daa710f73068;p=platform%2Fupstream%2Fllvm.git [libc++] Implement P2499R0 (`string_view` range constructor should be `explicit`) Reviewed By: #libc, philnik, Mordante Spies: Mordante, jloser, philnik, libcxx-commits Differential Revision: https://reviews.llvm.org/D130785 --- diff --git a/libcxx/docs/ReleaseNotes.rst b/libcxx/docs/ReleaseNotes.rst index f5ebc4e..e8f1f9d 100644 --- a/libcxx/docs/ReleaseNotes.rst +++ b/libcxx/docs/ReleaseNotes.rst @@ -37,6 +37,7 @@ What's New in Libc++ 16.0.0? Implemented Papers ------------------ +- P2499R0 - ``string_view`` range constructor should be ``explicit`` Improvements and New Features ----------------------------- diff --git a/libcxx/docs/Status/Cxx2bPapers.csv b/libcxx/docs/Status/Cxx2bPapers.csv index 4c5dd10d..c3a6331 100644 --- a/libcxx/docs/Status/Cxx2bPapers.csv +++ b/libcxx/docs/Status/Cxx2bPapers.csv @@ -79,7 +79,7 @@ "`P2467R1 `__","LWG","Support exclusive mode for ``fstreams``","July 2022","","" "`P2474R2 `__","LWG","``views::repeat``","July 2022","","" "`P2494R2 `__","LWG","Relaxing range adaptors to allow for move only types","July 2022","","" -"`P2499R0 `__","LWG","``string_view`` range constructor should be ``explicit``","July 2022","","" +"`P2499R0 `__","LWG","``string_view`` range constructor should be ``explicit``","July 2022","|Complete|","16.0" "`P2502R2 `__","LWG","``std::generator``: Synchronous Coroutine Generator for Ranges","July 2022","","" "`P2508R1 `__","LWG","Exposing ``std::basic-format-string``","July 2022","","" "`P2513R4 `__","LWG","``char8_t`` Compatibility and Portability Fixes","July 2022","","" diff --git a/libcxx/include/string_view b/libcxx/include/string_view index a84ed50..a9aa304 100644 --- a/libcxx/include/string_view +++ b/libcxx/include/string_view @@ -331,7 +331,7 @@ public: typename remove_reference_t<_Range>::traits_type; } || is_same_v::traits_type, _Traits>) ) - constexpr _LIBCPP_HIDE_FROM_ABI + constexpr explicit _LIBCPP_HIDE_FROM_ABI basic_string_view(_Range&& __r) : __data(ranges::data(__r)), __size(ranges::size(__r)) {} #endif // _LIBCPP_STD_VER > 20 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) diff --git a/libcxx/test/std/strings/string.view/string.view.cons/from_range.pass.cpp b/libcxx/test/std/strings/string.view/string.view.cons/from_range.pass.cpp index 83e96a4..a5533ea 100644 --- a/libcxx/test/std/strings/string.view/string.view.cons/from_range.pass.cpp +++ b/libcxx/test/std/strings/string.view/string.view.cons/from_range.pass.cpp @@ -98,13 +98,13 @@ constexpr bool test() { // Test that we're not trying to use the type's conversion operator to string_view in the constructor. { const DeletedConversionOperator d; - std::basic_string_view csv = d; + std::basic_string_view csv = std::basic_string_view(d); assert(csv == "test"); } { DeletedConstConversionOperator dc; - std::basic_string_view sv = dc; + std::basic_string_view sv = std::basic_string_view(dc); assert(sv == "test"); } @@ -186,6 +186,8 @@ void test_throwing() { } #endif +static_assert(!std::is_convertible_v, std::string_view>); + int main(int, char**) { test(); static_assert(test()); diff --git a/libcxx/test/std/strings/string.view/string.view.deduct/range.pass.cpp b/libcxx/test/std/strings/string.view/string.view.deduct/range.pass.cpp index 7efe9ef..38336db 100644 --- a/libcxx/test/std/strings/string.view/string.view.deduct/range.pass.cpp +++ b/libcxx/test/std/strings/string.view/string.view.deduct/range.pass.cpp @@ -44,7 +44,7 @@ void test() { contiguous_iterator begin() const { return contiguous_iterator(data_); } contiguous_iterator end() const { return contiguous_iterator(data_ + 3); } }; - std::basic_string_view bsv = Widget(); + std::basic_string_view bsv = std::basic_string_view(Widget()); ASSERT_SAME_TYPE(decltype(bsv), std::basic_string_view); }