https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107376
Bug ID: 107376
Summary: regex executor requires allocator to be default
constructible
Product: gcc
Version: 13.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: listcrawler at gmail dot com
Target Milestone: ---
To recreate problem:
#include <regex>
#include <memory>
template <typename T>
struct Alloc
{
using value_type = T;
T* allocate(std::size_t n)
{
return std::allocator<T>{}.allocate(n);
}
void deallocate(T* p, std::size_t n)
{
std::allocator<T>{}.deallocate(p, n);
}
~Alloc() = default;
//explicit Alloc() = default;
explicit Alloc(int) {}
Alloc(Alloc const&) = default;
Alloc(Alloc && rhs) = default;
Alloc& operator=(Alloc const&) = default;
Alloc& operator=(Alloc && rhs) = default;
template<typename U> Alloc(Alloc<U> const& rhs) {}
template<typename U> Alloc(Alloc<U> && rhs) {}
template<typename U> Alloc& operator=(Alloc<U> const& rhs) {}
template<typename U> Alloc& operator=(Alloc<U> && rhs) {}
};
template<typename T, typename U>
bool operator==(Alloc<T> const&, Alloc<U> const&)
{
return true;
}
template<typename T, typename U>
bool operator!=(Alloc<T> const&, Alloc<U> const&)
{
return false;
}
// ===========================================================================
template<typename T> using A = Alloc<T>;
using S = std::string;
using SIt = typename S::const_iterator;
using SubMatch = std::sub_match<SIt>;
using Match = std::match_results<SIt, A<SubMatch>>;
int main()
{
S s {"foo"};
Match m {A<SubMatch>{0}};
std::regex r {"foo"};
std::regex_match(s, m, r);
}
Suggested patch:
diff --git a/libstdc++-v3/include/bits/regex_executor.h
b/libstdc++-v3/include/bits/regex_executor.h
index dc0878ce6..080a1134e 100644
--- a/libstdc++-v3/include/bits/regex_executor.h
+++ b/libstdc++-v3/include/bits/regex_executor.h
@@ -71,7 +71,8 @@ namespace __detail
_ResultsVec& __results,
const _RegexT& __re,
_FlagT __flags)
- : _M_begin(__begin),
+ : _M_cur_results(__results.get_allocator())
+ , _M_begin(__begin),
_M_end(__end),
_M_re(__re),
_M_nfa(*__re._M_automaton),