From 494dad6b72d499ea832ab4b9b9bb76e0330e4eeb Mon Sep 17 00:00:00 2001 From: Joe Loser Date: Tue, 19 Oct 2021 14:18:36 -0400 Subject: [PATCH] [libc++][NFC] Mark LWG3573 as complete Mark LWG3573 as complete. It involves a change in wording around when `basic_string_view`'s constructor for iterator/sentinel can throw. The current implementation is not marked conditionally `noexcept`, so there is nothing to do here. Add a test that binds this behavior to verify the constructor is not marked `noexcept(true)` when `end - begin` throws. Reviewed By: ldionne, Mordante, #libc Differential Revision: https://reviews.llvm.org/D111925 --- libcxx/docs/Status/Cxx2bIssues.csv | 2 +- .../from_iterator_sentinel.pass.cpp | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/libcxx/docs/Status/Cxx2bIssues.csv b/libcxx/docs/Status/Cxx2bIssues.csv index 97c560407c0f..93ef7246eb52 100644 --- a/libcxx/docs/Status/Cxx2bIssues.csv +++ b/libcxx/docs/Status/Cxx2bIssues.csv @@ -125,7 +125,7 @@ `3570 `__,"``basic_osyncstream::emit`` should be an unformatted output function","October 2021","","" `3571 `__,"``flush_emit`` should set ``badbit`` if the ``emit`` call fails","October 2021","","" `3572 `__,"``copyable-box`` should be fully ``constexpr``","October 2021","","","|ranges|" -`3573 `__,"Missing Throws element for ``basic_string_view(It begin, End end)``","October 2021","","" +`3573 `__,"Missing Throws element for ``basic_string_view(It begin, End end)``","October 2021","|Complete|","14.0" `3574 `__,"``common_iterator`` should be completely ``constexpr``-able","October 2021","","","|ranges|" `3580 `__,"``iota_view``'s ``iterator``'s binary ``operator+`` should be improved","October 2021","","","|ranges|" `3581 `__,"The range constructor makes ``basic_string_view`` not trivially move constructible","October 2021","","","|ranges|" diff --git a/libcxx/test/std/strings/string.view/string.view.cons/from_iterator_sentinel.pass.cpp b/libcxx/test/std/strings/string.view/string.view.cons/from_iterator_sentinel.pass.cpp index e7a9e0a836db..f53018c5c8e0 100644 --- a/libcxx/test/std/strings/string.view/string.view.cons/from_iterator_sentinel.pass.cpp +++ b/libcxx/test/std/strings/string.view/string.view.cons/from_iterator_sentinel.pass.cpp @@ -16,6 +16,7 @@ #include #include +#include #include #include "make_string.h" @@ -43,6 +44,36 @@ constexpr bool test() { return true; } +#ifndef TEST_HAS_NO_EXCEPTIONS +template +struct ThrowingSentinel { + friend bool operator==(const CharT*, ThrowingSentinel) noexcept { return true; } + friend std::iter_difference_t operator-(const CharT*, ThrowingSentinel) noexcept { return {}; } + friend std::iter_difference_t operator-(ThrowingSentinel, const CharT*) { throw 42; } +}; + +template +void test_throwing() { + auto val = MAKE_STRING_VIEW(CharT, "test"); + try { + (void)std::basic_string_view(val.begin(), ThrowingSentinel()); + assert(false); + } catch (int i) { + assert(i == 42); + } +} + +void test_throwing() { + test_throwing(); +#ifndef TEST_HAS_NO_WIDE_CHARACTERS + test_throwing(); +#endif + test_throwing(); + test_throwing(); + test_throwing(); +} +#endif + static_assert( std::is_constructible_v); static_assert( std::is_constructible_v); static_assert(!std::is_constructible_v); // not a sentinel @@ -54,6 +85,10 @@ int main(int, char**) { test(); static_assert(test()); +#ifndef TEST_HAS_NO_EXCEPTIONS + test_throwing(); +#endif + return 0; }