public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "ammiera at hotmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/114316] New: assert failure with _GLIBCXX_DEBUG and empty range of singular iterators passed std:: algorithm
Date: Tue, 12 Mar 2024 09:05:43 +0000	[thread overview]
Message-ID: <bug-114316-4@http.gcc.gnu.org/bugzilla/> (raw)

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114316

            Bug ID: 114316
           Summary: assert failure with _GLIBCXX_DEBUG and empty range of
                    singular iterators passed std:: algorithm
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ammiera at hotmail dot com
  Target Milestone: ---

Compiling the attached snippet with -D_GLIBCXX_DEBUG causes an assert to fire:

#include <map>
#include <algorithm>
#include <iterator>

int main()
{
    std::multimap<char, int>::iterator it1{};
    std::multimap<char, int>::iterator it2{};

    (void) (it1==it2); // OK
    (void) std::find_if(
        it1, it2, [](const auto& el) { return el.second == 8;});
}

The runtime error:

In function:
    constexpr _IIter std::find_if(_IIter, _IIter, _Predicate) [with _IIter = 
    gnu_debug::_Safe_iterator<_Rb_tree_iterator<pair<const char, int> >, 
    debug::multimap<char, int>, bidirectional_iterator_tag>; _Predicate = 
    main()::<lambda(const auto:16&)>]

Error: function requires a valid iterator range [first, last).

Objects involved in the operation:
    iterator "first" @ 0x7ffc275311a0 {
      type = std::_Rb_tree_iterator<std::pair<char const, int> > (mutable
iterator);
      state = singular;
    }
    iterator "last" @ 0x7ffc275311d0 {
      type = std::_Rb_tree_iterator<std::pair<char const, int> > (mutable
iterator);
      state = singular;
    }
Program terminated with signal: SIGSEGV

https://godbolt.org/z/e8xa5Eoqn

Tested with C++17 and C++20 mode.

Initially discussed on the mailing list:
https://gcc.gnu.org/pipermail/libstdc++/2024-March/058461.html

             reply	other threads:[~2024-03-12  9:05 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-12  9:05 ammiera at hotmail dot com [this message]
2024-03-12  9:46 ` [Bug libstdc++/114316] assert failure with _GLIBCXX_DEBUG and empty range of singular iterators passed to " redi at gcc dot gnu.org
2024-03-12 13:08 ` redi at gcc dot gnu.org
2024-03-17 15:42 ` cvs-commit at gcc dot gnu.org
2024-03-17 15:47 ` cvs-commit at gcc dot gnu.org
2024-03-20  6:07 ` fdumont at gcc dot gnu.org
2024-03-25 12:17 ` 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-114316-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).