public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/107376] New: regex executor requires allocator to be default constructible
@ 2022-10-24 12:46 listcrawler at gmail dot com
  2022-10-24 23:33 ` [Bug libstdc++/107376] " redi at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: listcrawler at gmail dot com @ 2022-10-24 12:46 UTC (permalink / raw)
  To: gcc-bugs

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),

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-03-18 14:15 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-24 12:46 [Bug libstdc++/107376] New: regex executor requires allocator to be default constructible listcrawler at gmail dot com
2022-10-24 23:33 ` [Bug libstdc++/107376] " redi at gcc dot gnu.org
2022-10-25 10:18 ` redi at gcc dot gnu.org
2022-10-28 14:27 ` cvs-commit at gcc dot gnu.org
2022-10-28 14:48 ` redi at gcc dot gnu.org
2024-03-18 14:06 ` cvs-commit at gcc dot gnu.org
2024-03-18 14:15 ` redi at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).