public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/109122] std::ranges::find segfaults with gcc (trunk but not 12.2) on godbolt
Date: Tue, 14 Mar 2023 10:12:33 +0000	[thread overview]
Message-ID: <bug-109122-4-FViU6gS7fU@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-109122-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
As requested when creating a bug, please read https://gcc.gnu.org/bugs/ which
says to provide the testcase, not a URL to somewhere else.

#include <cstdio>
#include <ranges>
#include <vector>
#include <concepts>
#include <cstring>

namespace rng = std::ranges;

struct entity
{
    entity(int nr)
        :   nr_{ nr }
    {}

    auto get_nr() -> int { return  nr_; }

    int nr_;
};

    // inline constexpr auto str_prefix() -> std::string_view { return
"realtime"; };



int main()
{
    const std::vector<entity> vec = { 1,2,3};

    auto it = rng::find(vec, 2, &entity::get_nr);
    // auto it = rng::find_if(vec, [](int e){ return e == 2; },
&entity::get_nr);
    if constexpr (std::same_as<decltype(it),
std::vector<entity>::const_iterator>) {
        printf("Const iterator was chosen!\n");
    } else if constexpr (std::same_as<decltype(it),
std::vector<entity>::iterator>) {
        printf("Normal iterator was chosen!\n");
    }
    if (it != vec.end()) {
        printf("found vec element %d\n", it->nr_);
    }
}


109122.cc: In function 'int main()':
109122.cc:28:24: error: no match for call to '(const std::ranges::__find_fn)
(const std::vector<entity>&, int, int (entity::*)())'
   28 |     auto it = rng::find(vec, 2, &entity::get_nr);
      |               ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /home/jwakely/gcc/13/include/c++/13.0.1/tuple:44,
                 from
/home/jwakely/gcc/13/include/c++/13.0.1/bits/uses_allocator_args.h:38,
                 from
/home/jwakely/gcc/13/include/c++/13.0.1/bits/memory_resource.h:41,
                 from /home/jwakely/gcc/13/include/c++/13.0.1/string:58,
                 from
/home/jwakely/gcc/13/include/c++/13.0.1/bits/locale_classes.h:40,
                 from
/home/jwakely/gcc/13/include/c++/13.0.1/bits/ios_base.h:41,
                 from /home/jwakely/gcc/13/include/c++/13.0.1/streambuf:43,
                 from
/home/jwakely/gcc/13/include/c++/13.0.1/bits/streambuf_iterator.h:35,
                 from /home/jwakely/gcc/13/include/c++/13.0.1/iterator:66,
                 from /home/jwakely/gcc/13/include/c++/13.0.1/ranges:43,
                 from 109122.cc:2:
/home/jwakely/gcc/13/include/c++/13.0.1/bits/ranges_util.h:445:7: note:
candidate: 'template<class _Iter, class _Sent, class _Tp, class _Proj> 
requires (input_iterator<_Iter>) && (sentinel_for<_Sent, _Iter>) &&
(indirect_binary_predicate<std::ranges::equal_to, std::projected<_I1, _P1>,
const _Tp*>) constexpr _Iter std::ranges::__find_fn::operator()(_Iter, _Sent,
const _Tp&, _Proj) const'
  445 |       operator()(_Iter __first, _Sent __last,
      |       ^~~~~~~~
/home/jwakely/gcc/13/include/c++/13.0.1/bits/ranges_util.h:445:7: note:  
template argument deduction/substitution failed:
/home/jwakely/gcc/13/include/c++/13.0.1/bits/ranges_util.h:445:7: note:
constraints not satisfied
In file included from
/home/jwakely/gcc/13/include/c++/13.0.1/bits/stl_iterator_base_types.h:71,
                 from /home/jwakely/gcc/13/include/c++/13.0.1/iterator:61:
/home/jwakely/gcc/13/include/c++/13.0.1/bits/iterator_concepts.h: In
substitution of 'template<class _Iter, class _Sent, class _Tp, class _Proj> 
requires (input_iterator<_Iter>) && (sentinel_for<_Sent, _Iter>) &&
(indirect_binary_predicate<std::ranges::equal_to, std::projected<_I1, _P1>,
const _Tp*>) constexpr _Iter std::ranges::__find_fn::operator()(_Iter, _Sent,
const _Tp&, _Proj) const [with _Iter = std::vector<entity>; _Sent = int; _Tp =
int (entity::*)(); _Proj = std::identity]':
109122.cc:28:24:   required from here
/home/jwakely/gcc/13/include/c++/13.0.1/bits/iterator_concepts.h:634:13:  
required for the satisfaction of 'input_or_output_iterator<_Iter>' [with _Iter
= std::vector<entity, std::allocator<entity> >]
/home/jwakely/gcc/13/include/c++/13.0.1/bits/iterator_concepts.h:656:13:  
required for the satisfaction of 'input_iterator<_Iter>' [with _Iter =
std::vector<entity, std::allocator<entity> >]
/home/jwakely/gcc/13/include/c++/13.0.1/bits/iterator_concepts.h:635:9:   in
requirements with '_Iter __i' [with _Iter = std::vector<entity,
std::allocator<entity> >]
/home/jwakely/gcc/13/include/c++/13.0.1/bits/iterator_concepts.h:635:33: note:
the required expression '* __i' is invalid
  635 |       = requires(_Iter __i) { { *__i } -> __detail::__can_reference; }
      |                                 ^~~~
cc1plus: note: set '-fconcepts-diagnostics-depth=' to at least 2 for more
detail
/home/jwakely/gcc/13/include/c++/13.0.1/bits/ranges_util.h:459:7: note:
candidate: 'template<class _Range, class _Tp, class _Proj>  requires
(input_range<_Range>) && (indirect_binary_predicate<std::ranges::equal_to,
std::projected<decltype(std::ranges::__cust_access::__begin((declval<_Container&>)())),
_Proj>, const _Tp*>) constexpr std::ranges::borrowed_iterator_t<_Range>
std::ranges::__find_fn::operator()(_Range&&, const _Tp&, _Proj) const'
  459 |       operator()(_Range&& __r, const _Tp& __value, _Proj __proj = {})
const
      |       ^~~~~~~~
/home/jwakely/gcc/13/include/c++/13.0.1/bits/ranges_util.h:459:7: note:  
template argument deduction/substitution failed:
/home/jwakely/gcc/13/include/c++/13.0.1/bits/ranges_util.h:459:7: note:
constraints not satisfied
109122.cc: In substitution of 'template<class _Range, class _Tp, class _Proj> 
requires (input_range<_Range>) &&
(indirect_binary_predicate<std::ranges::equal_to,
std::projected<decltype(std::ranges::__cust_access::__begin((declval<_Container&>)())),
_Proj>, const _Tp*>) constexpr std::ranges::borrowed_iterator_t<_Range>
std::ranges::__find_fn::operator()(_Range&&, const _Tp&, _Proj) const [with
_Range = const std::vector<entity>&; _Tp = int; _Proj = int (entity::*)()]':
109122.cc:28:24:   required from here
/home/jwakely/gcc/13/include/c++/13.0.1/bits/iterator_concepts.h:533:13:  
required for the satisfaction of '__indirectly_readable_impl<typename
std::remove_cvref<_Tp>::type>' [with _In =
std::projected<decltype(std::ranges::__cust_access::__begin((declval<_Container&>)())),
_Proj>]
/home/jwakely/gcc/13/include/c++/13.0.1/bits/iterator_concepts.h:553:13:  
required for the satisfaction of 'indirectly_readable<_I1>' [with _I1 =
std::projected<decltype(std::ranges::__cust_access::__begin((declval<_Container&>)())),
_Proj>]
/home/jwakely/gcc/13/include/c++/13.0.1/bits/iterator_concepts.h:736:13:  
required for the satisfaction of
'indirect_binary_predicate<std::ranges::equal_to, std::projected<decltype
(std::ranges::__cust_access::__begin(declval<_Container&>())), _Proj>, const
_Tp*>' [with _Range = const std::vector<entity, std::allocator<entity> >&;
_Proj = int (entity::*)(); _Tp = int]
109122.cc:28:24: error: template constraint failure for 'template<class _Iter,
class _Proj>  requires (indirectly_readable<_Iter>) &&
(indirectly_regular_unary_invocable<_Proj, _Iter>) struct std::projected'
   28 |     auto it = rng::find(vec, 2, &entity::get_nr);
      |               ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
109122.cc:28:24: note: constraints not satisfied
'
g++: internal compiler error: Segmentation fault signal terminated program
cc1plus
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
See <https://gcc.gnu.org/bugs/> for instructions.


It segfaults with GCC 12 too, but only for --enable-checking builds.

  reply	other threads:[~2023-03-14 10:12 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-14  9:10 [Bug c++/109122] New: " samuel.beer at gmx dot ch
2023-03-14 10:12 ` redi at gcc dot gnu.org [this message]
2023-03-14 10:15 ` [Bug c++/109122] " redi at gcc dot gnu.org
2023-03-14 14:33 ` mpolacek at gcc dot gnu.org
2023-03-14 14:42 ` mpolacek at gcc dot gnu.org
2023-11-10 19:45 ` pinskia at gcc dot gnu.org
2023-11-10 21:22 ` ppalka 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-109122-4-FViU6gS7fU@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).