public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "listcrawler at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/107376] New: regex executor requires allocator to be default constructible
Date: Mon, 24 Oct 2022 12:46:50 +0000	[thread overview]
Message-ID: <bug-107376-4@http.gcc.gnu.org/bugzilla/> (raw)

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

             reply	other threads:[~2022-10-24 12:46 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-24 12:46 listcrawler at gmail dot com [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-107376-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).