From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 4E8E33858D39; Tue, 14 Mar 2023 10:12:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4E8E33858D39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678788754; bh=nrTpo7h4B/ivwEJ3Led4bAQh8rKlbJ6TRMKI3P5Y6eY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=w70uszchjPxKysqF7eJlpK15uB2gsNWV0r20wh7y8UpQRfc/UBYdGowaGv5w7Z/k+ if+BtNm4ZuslXjNU1VViIqDQkGh9MX5Gs7L6IGNGVLsC9sWFWH5oqx75/qhvqVCpSV IVdSw9kSIhNC75/VqLtabDVx/BfJvkl9jLaQD2BE= From: "redi at gcc dot 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: ice-on-invalid-code X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D109122 --- Comment #1 from Jonathan Wakely --- As requested when creating a bug, please read https://gcc.gnu.org/bugs/ whi= ch says to provide the testcase, not a URL to somewhere else. #include #include #include #include #include namespace rng =3D 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 vec =3D { 1,2,3}; auto it =3D rng::find(vec, 2, &entity::get_nr); // auto it =3D rng::find_if(vec, [](int e){ return e =3D=3D 2; }, &entity::get_nr); if constexpr (std::same_as::const_iterator>) { printf("Const iterator was chosen!\n"); } else if constexpr (std::same_as::iterator>) { printf("Normal iterator was chosen!\n"); } if (it !=3D 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&, int, int (entity::*)())' 28 | auto it =3D 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=20 requires (input_iterator<_Iter>) && (sentinel_for<_Sent, _Iter>) && (indirect_binary_predicate, const _Tp*>) constexpr _Iter std::ranges::__find_fn::operator()(_Iter, _Sen= t, 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:=20= =20 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= =20 requires (input_iterator<_Iter>) && (sentinel_for<_Sent, _Iter>) && (indirect_binary_predicate, const _Tp*>) constexpr _Iter std::ranges::__find_fn::operator()(_Iter, _Sen= t, const _Tp&, _Proj) const [with _Iter =3D std::vector; _Sent =3D int= ; _Tp =3D int (entity::*)(); _Proj =3D std::identity]': 109122.cc:28:24: required from here /home/jwakely/gcc/13/include/c++/13.0.1/bits/iterator_concepts.h:634:13:=20= =20 required for the satisfaction of 'input_or_output_iterator<_Iter>' [with _I= ter =3D std::vector >] /home/jwakely/gcc/13/include/c++/13.0.1/bits/iterator_concepts.h:656:13:=20= =20 required for the satisfaction of 'input_iterator<_Iter>' [with _Iter =3D std::vector >] /home/jwakely/gcc/13/include/c++/13.0.1/bits/iterator_concepts.h:635:9: in requirements with '_Iter __i' [with _Iter =3D std::vector >] /home/jwakely/gcc/13/include/c++/13.0.1/bits/iterator_concepts.h:635:33: no= te: the required expression '* __i' is invalid 635 | =3D requires(_Iter __i) { { *__i } -> __detail::__can_referen= ce; } | ^~~~ cc1plus: note: set '-fconcepts-diagnostics-depth=3D' 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 requires (input_range<_Range>) && (indirect_binary_predicate)())), _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 =3D= {}) const | ^~~~~~~~ /home/jwakely/gcc/13/include/c++/13.0.1/bits/ranges_util.h:459:7: note:=20= =20 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=20 requires (input_range<_Range>) && (indirect_binary_predicate)())), _Proj>, const _Tp*>) constexpr std::ranges::borrowed_iterator_t<_Range> std::ranges::__find_fn::operator()(_Range&&, const _Tp&, _Proj) const [with _Range =3D const std::vector&; _Tp =3D int; _Proj =3D int (entity::= *)()]': 109122.cc:28:24: required from here /home/jwakely/gcc/13/include/c++/13.0.1/bits/iterator_concepts.h:533:13:=20= =20 required for the satisfaction of '__indirectly_readable_impl::type>' [with _In =3D std::projected)())), _Proj>] /home/jwakely/gcc/13/include/c++/13.0.1/bits/iterator_concepts.h:553:13:=20= =20 required for the satisfaction of 'indirectly_readable<_I1>' [with _I1 =3D std::projected)())), _Proj>] /home/jwakely/gcc/13/include/c++/13.0.1/bits/iterator_concepts.h:736:13:=20= =20 required for the satisfaction of 'indirect_binary_predicate())), _Proj>, const _Tp*>' [with _Range =3D const std::vector >&; _Proj =3D int (entity::*)(); _Tp =3D int] 109122.cc:28:24: error: template constraint failure for 'template requires (indirectly_readable<_Iter>) && (indirectly_regular_unary_invocable<_Proj, _Iter>) struct std::projected' 28 | auto it =3D 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 for instructions. It segfaults with GCC 12 too, but only for --enable-checking builds.=