public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "db0451 at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/94973] New: compile error when trying to use pointer-to-member function as invokable projection to ranges::find()
Date: Wed, 06 May 2020 15:03:46 +0000 [thread overview]
Message-ID: <bug-94973-4@http.gcc.gnu.org/bugzilla/> (raw)
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94973
Bug ID: 94973
Summary: compile error when trying to use pointer-to-member
function as invokable projection to ranges::find()
Product: gcc
Version: 9.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: db0451 at gmail dot com
Target Milestone: ---
`range-v3` has the concept of "invocable projections", i.e. simple
transformations that can be applied as predicates to its algorithms.
Pointer-to-member-functions should be included and mean 'get the result of
calling that on the current element'. However, it seems that invoking a
pointer-to-member-function in g++ (but NOT clang++) causes the build to fail.
Given the code, compiled with `g++ -std=c++17` against `ericniebler/range-v3`
release `range-v3-0.10.0`, using `g++.exe (Rev2, Built by MSYS2 project)
9.3.0`:
```cpp
#include <range/v3/algorithm/find.hpp>
#include <vector>
auto
main() -> int
{
struct S {
int i{};
auto get_i() const { return i; }
};
auto const ss = std::vector<S>(10);
ranges::find(ss, 1, &S::get_i);
return 0;
}
```
I get a spew of errors:
```none
test.cpp: In function 'int main()':
test.cpp:14:31: error: no match for call to '(const ranges::find_fn) (const
std::vector<main()::S>&, int, int (main()::S::*)() const)'
14 | ranges::find(ss, 1, &S::get_i);
| ^
In file included from FOO/include/range-v3/range/v3/range_fwd.hpp:24,
from FOO/include/range-v3/range/v3/algorithm/find.hpp:18,
from test.cpp:1:
FOO/include/range-v3/range/v3/detail/config.hpp:618:27: note: candidate:
'template<class I, class S, class V, class P> constexpr concepts::return_t<I,
typename std::enable_if<(((input_iterator<I> && sentinel_for<S, I>) &&
indirect_relation<ranges::equal_to, typename
ranges::detail::select_projected_<P>::apply<I>, const V*>) &&
concepts::detail::CPP_true(concepts::detail::Nil{})), void>::type>
ranges::find_fn::operator()(I, S, const V&, P) const'
618 | #define RANGES_FUNC(NAME) operator() RANGES_FUNC_CONST_ /**/
| ^~~~~~~~
FOO/include/range-v3/range/v3/algorithm/find.hpp:47:24: note: in expansion of
macro 'RANGES_FUNC'
47 | constexpr auto RANGES_FUNC(find)(I first, S last, V const &
val, P proj = P{})
| ^~~~~~~~~~~
FOO/include/range-v3/range/v3/detail/config.hpp:618:27: note: template
argument deduction/substitution failed:
618 | #define RANGES_FUNC(NAME) operator() RANGES_FUNC_CONST_ /**/
| ^~~~~~~~
FOO/include/range-v3/range/v3/algorithm/find.hpp:47:24: note: in expansion of
macro 'RANGES_FUNC'
47 | constexpr auto RANGES_FUNC(find)(I first, S last, V const &
val, P proj = P{})
| ^~~~~~~~~~~
In file included from FOO/include/range-v3/range/v3/iterator/access.hpp:22,
from FOO/include/range-v3/range/v3/iterator/concepts.hpp:30,
from FOO/include/range-v3/range/v3/algorithm/find.hpp:22,
from test.cpp:1:
FOO/include/range-v3/std/detail/associated_types.hpp: In substitution of
'template<bool B, class T> using enable_if_t = typename
ranges::detail::enable_if::apply<T> [with bool B =
ranges::readable<std::vector<main()::S> >; T = std::vector<main()::S>]':
FOO/include/range-v3/range/v3/iterator/concepts.hpp:561:19: required by
substitution of 'template<class I> using apply =
ranges::detail::enable_if_t<(bool)(readable<I>), I> [with I =
std::vector<main()::S>]'
FOO/include/range-v3/range/v3/algorithm/find.hpp:48:15: required by
substitution of 'template<class I, class S, class V, class P> constexpr
concepts::return_t<I, typename std::enable_if<(((input_iterator<I> &&
sentinel_for<S, I>) && indirect_relation<ranges::equal_to, typename
ranges::detail::select_projected_<P>::apply<I>, const V*>) &&
concepts::detail::CPP_true(concepts::detail::Nil{})), void>::type>
ranges::find_fn::operator()(I, S, const V&, P) const [with I =
std::vector<main()::S>; S = int; V = int (main()::S::*)() const; P =
ranges::identity]'
test.cpp:14:31: required from here
FOO/include/range-v3/std/detail/associated_types.hpp:73:15: error: no class
template named 'apply' in 'struct ranges::detail::enable_if<false>'
73 | using enable_if_t = typename enable_if<B>::template apply<T>;
| ^~~~~~~~~~~
In file included from FOO/include/range-v3/range/v3/range_fwd.hpp:24,
from FOO/include/range-v3/range/v3/algorithm/find.hpp:18,
from test.cpp:1:
FOO/include/range-v3/range/v3/detail/config.hpp:618:27: note: candidate:
'template<class Rng, class V, class P> constexpr concepts::return_t<typename
ranges::detail::if_then<forwarding_range_<R> >::apply<decltype
(ranges::_::begin(declval<Rng&>())), ranges::dangling>, typename
std::enable_if<((input_range<Rng> && indirect_relation<ranges::equal_to,
typename ranges::detail::select_projected_<P1>::apply<decltype
(ranges::_::begin(declval<Rng&>()))>, const V*>) &&
concepts::detail::CPP_true(concepts::detail::Nil{})), void>::type>
ranges::find_fn::operator()(Rng&&, const V&, P) const'
618 | #define RANGES_FUNC(NAME) operator() RANGES_FUNC_CONST_ /**/
| ^~~~~~~~
FOO/include/range-v3/range/v3/algorithm/find.hpp:60:24: note: in expansion of
macro 'RANGES_FUNC'
60 | constexpr auto RANGES_FUNC(find)(Rng && rng, V const & val, P
proj = P{})
| ^~~~~~~~~~~
FOO/include/range-v3/range/v3/detail/config.hpp:618:27: note: template
argument deduction/substitution failed:
618 | #define RANGES_FUNC(NAME) operator() RANGES_FUNC_CONST_ /**/
| ^~~~~~~~
FOO/include/range-v3/range/v3/algorithm/find.hpp:60:24: note: in expansion of
macro 'RANGES_FUNC'
60 | constexpr auto RANGES_FUNC(find)(Rng && rng, V const & val, P
proj = P{})
| ^~~~~~~~~~~
In file included from FOO/include/range-v3/range/v3/iterator/access.hpp:22,
from FOO/include/range-v3/range/v3/iterator/concepts.hpp:30,
from FOO/include/range-v3/range/v3/algorithm/find.hpp:22,
from test.cpp:1:
FOO/include/range-v3/std/detail/associated_types.hpp: In substitution of
'template<bool B, class T> using enable_if_t = typename
ranges::detail::enable_if::apply<T> [with bool B =
ranges::indirectly_regular_unary_invocable<int (main()::S::*)() const,
__gnu_cxx::__normal_iterator<const main()::S*, std::vector<main()::S> > >; T =
ranges::detail::projected_<__gnu_cxx::__normal_iterator<const main()::S*,
std::vector<main()::S> >, int (main()::S::*)() const>]':
FOO/include/range-v3/range/v3/iterator/concepts.hpp:552:19: required by
substitution of 'template<class Proj> template<class I> using apply =
ranges::detail::enable_if_t<(bool)(indirectly_regular_unary_invocable<Proj,
I>), ranges::detail::projected_<I, Proj> > [with I =
__gnu_cxx::__normal_iterator<const main()::S*, std::vector<main()::S> >; Proj =
int (main()::S::*)() const]'
FOO/include/range-v3/range/v3/algorithm/find.hpp:61:15: required by
substitution of 'template<class Rng, class V, class P> constexpr
concepts::return_t<typename ranges::detail::if_then<forwarding_range_<R>
>::apply<decltype (ranges::_::begin(declval<Rng&>())), ranges::dangling>,
typename std::enable_if<((input_range<Rng> &&
indirect_relation<ranges::equal_to, typename
ranges::detail::select_projected_<P1>::apply<decltype
(ranges::_::begin(declval<Rng&>()))>, const V*>) &&
concepts::detail::CPP_true(concepts::detail::Nil{})), void>::type>
ranges::find_fn::operator()(Rng&&, const V&, P) const [with Rng = const
std::vector<main()::S>&; V = int; P = int (main()::S::*)() const]'
test.cpp:14:31: required from here
FOO/include/range-v3/std/detail/associated_types.hpp:73:15: error: no class
template named 'apply' in 'struct ranges::detail::enable_if<false>'
73 | using enable_if_t = typename enable_if<B>::template apply<T>;
| ^~~~~~~~~~~
shell returned 1
```
* Making the projection a lambda works but seems wasted typing.
* Referring directly to the data member works but is not possible if it should
be encapsulated behind a const getter, transformer, etc.
* `clang++` (also on MSYS2) **does** work here. So I guess this must be a bug
in `g++`.
next reply other threads:[~2020-05-06 15:03 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-06 15:03 db0451 at gmail dot com [this message]
2020-05-06 15:24 ` [Bug libstdc++/94973] " redi at gcc dot gnu.org
2020-05-06 15:40 ` redi at gcc dot gnu.org
2020-05-06 15:48 ` db0451 at gmail dot com
2020-05-06 15:50 ` db0451 at gmail dot com
2020-05-06 16:03 ` [Bug c++/94973] " redi at gcc dot gnu.org
2020-05-06 16:04 ` redi at gcc dot gnu.org
2020-05-06 16:16 ` redi at gcc dot gnu.org
2020-05-06 16:17 ` db0451 at gmail dot com
2020-05-06 16:18 ` redi at gcc dot gnu.org
2020-05-06 16:26 ` redi at gcc dot gnu.org
2020-05-06 16:27 ` redi at gcc dot gnu.org
2020-05-06 16:30 ` redi at gcc dot gnu.org
2020-05-06 16:32 ` rguenth at gcc dot gnu.org
2020-05-06 16:39 ` redi at gcc dot gnu.org
2020-05-06 16:42 ` db0451 at gmail dot com
2020-05-06 16:46 ` db0451 at gmail dot com
2020-05-06 16:47 ` 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-94973-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).