Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions stl/inc/regex
Original file line number Diff line number Diff line change
Expand Up @@ -983,9 +983,19 @@ public:
using char_type = typename iterator_traits<_BidIt>::value_type;
using string_type = basic_string<char_type>;

match_results() : _Org(), _Ready(false) {}
match_results() = default;

explicit match_results(const _Alloc& _Al) : _Org(), _Ready(false), _Matches(_Al) {}
explicit match_results(const _Alloc& _Al) : _Matches(_Al) {}

match_results(const match_results& _Other, const _Alloc& _Al)
: _Org(_Other._Org), _Ready(_Other._Ready), _Matches(_Other._Matches, _Al), _Prefix(_Other._Prefix),
_Suffix(_Other._Suffix), _Null_elem(_Other._Null_elem) {}

match_results(match_results&& _Other, const _Alloc& _Al) noexcept(
conjunction_v<typename _Mytraits::is_always_equal, is_nothrow_move_constructible<_BidIt>>) // strengthened
: _Org(_STD move(_Other._Org)), _Ready(_Other._Ready), _Matches(_STD move(_Other._Matches), _Al),
_Prefix(_STD move(_Other._Prefix)), _Suffix(_STD move(_Other._Suffix)),
_Null_elem(_STD move(_Other._Null_elem)) {}

_NODISCARD bool ready() const noexcept /* strengthened */ {
return _Ready;
Expand Down Expand Up @@ -1126,8 +1136,8 @@ public:
return _Matches[_Sub];
}

_BidIt _Org;
bool _Ready;
_BidIt _Org = _BidIt();
bool _Ready = false;

private:
_MyCont _Matches;
Expand Down
41 changes: 41 additions & 0 deletions tests/std/tests/VSO_0000000_regex_interface/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
#include <regex>
#include <sstream>
#include <string>
#include <type_traits>

#if _HAS_CXX17
#include <memory_resource>
#endif // _HAS_CXX17

using namespace std;
using namespace std::regex_constants;
Expand Down Expand Up @@ -156,6 +161,41 @@ void test_dev10_505773_default_constructed_regex_should_not_match_empty_string()
assert(!regex_match("", r));
}

void test_LWG_2195_allocator_extended_ctors_for_match_result() {
constexpr char input[] = {'a', 'b', '\0', 'c', 'd'};
const regex pattern(".(.).*");

{
cmatch results;
assert(regex_match(begin(input), end(input), results, pattern));

cmatch r1{results, cmatch::allocator_type{}};
assert(r1 == results);

cmatch r2{move(results), cmatch::allocator_type{}};
assert(r2 == r1);

// strengthened exception specification
static_assert(is_nothrow_constructible_v<cmatch, cmatch, cmatch::allocator_type>,
"Allocator-extended move construction should be noexcept when the allocator is stateless.");
}
#if _HAS_CXX17
{
pmr::cmatch results;
assert(regex_match(begin(input), end(input), results, pattern));

pmr::cmatch r1{results, pmr::cmatch::allocator_type{}};
assert(r1 == results);

pmr::cmatch r2{move(results), pmr::cmatch::allocator_type{}};
assert(r2 == r1);

static_assert(!is_nothrow_constructible_v<pmr::cmatch, pmr::cmatch, pmr::cmatch::allocator_type>,
"Allocator-extended move construction shouldn't be noexcept when the allocator is stateful.");
}
#endif // _HAS_CXX17
}

template <typename ContainerT>
void test_LWG_2217_sub_match_should_not_slice_nulls() {
// LWG-2217: "operator==(sub_match, string) slices on embedded '\0's"
Expand Down Expand Up @@ -393,6 +433,7 @@ int main() {
test_dev10_900584_should_handle_quantified_alternates();
test_devdiv_903531_regex_should_have_correct_suffix_matching();
test_dev10_505773_default_constructed_regex_should_not_match_empty_string();
test_LWG_2195_allocator_extended_ctors_for_match_result();
test_LWG_2217_sub_match_should_not_slice_nulls<string>();
test_LWG_2217_sub_match_should_not_slice_nulls<list<char>>();
test_VSO_177524_sub_match_compare_should_not_construct_unnecessary_basic_strings<string>();
Expand Down