File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed
include/boost/url/grammar Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -159,7 +159,7 @@ class string_view_base
159159 */
160160 explicit
161161 operator
162- std::string () const noexcept
162+ std::string () const
163163 {
164164 return std::string (s_);
165165 }
Original file line number Diff line number Diff line change @@ -16,11 +16,40 @@ namespace boost {
1616namespace urls {
1717namespace grammar {
1818
19+ // Minimal derived class for testing
20+ struct test_string_view
21+ : string_view_base
22+ {
23+ explicit
24+ test_string_view (
25+ core::string_view s) noexcept
26+ : string_view_base(s)
27+ {
28+ }
29+ };
30+
1931struct string_view_base_test
2032{
2133 void
2234 run ()
2335 {
36+ // operator std::string() allocates
37+ static_assert (
38+ !noexcept (std::string (
39+ std::declval<test_string_view const &>())),
40+ " operator std::string() must not be noexcept" );
41+
42+ // Verify the conversion still works correctly
43+ {
44+ test_string_view sv (" hello" );
45+ std::string s = static_cast <std::string>(sv);
46+ BOOST_TEST (s == " hello" );
47+ }
48+ {
49+ test_string_view sv (" " );
50+ std::string s = static_cast <std::string>(sv);
51+ BOOST_TEST (s.empty ());
52+ }
2453 }
2554};
2655
You can’t perform that action at this time.
0 commit comments