request for member ‘operator()’ is ambiguous

57 views
Skip to first unread message

Vicente J. Botet Escriba

unread,
Sep 26, 2015, 12:27:28 PM9/26/15
to std-dis...@isocpp.org
Hi,

In [1] Evans proposes to use expansion inheritance in line (*)

#ifdef __clang__
template<typename... Functors>
struct overloader : forwarder<Functors>...  // (*)
{
  overloader(Functors&&... functors_a)
  : forwarder<Functors>(functors_a)...
  {}  
};
#else
template<typename... Functors>
struct overloader;
template<>
struct overloader<>
{
  void operator()()
  {
  }
};

template<typename Functor0, typename... Functors>
struct overloader<Functor0, Functors...>
: forwarder<Functor0>, overloader<Functors...>
{
  overloader(Functor0&& functor0, Functors&&... functors_a)
  : forwarder<Functor0>(std::forward<Functor0>(functor0))
  , overloader<Functors...>(std::forward<Functors>(functors_a)...)
  {}
  using forwarder<Functor0>::operator();
  using overloader<Functors...>::operator();
};
#endif

The code after #ifdef __clang__ fails to compile with gcc, with the following compile error

error: request for member ‘operator()’ is ambiguous ovldr(udt_i<0>{});

IMO it is missing something like the line  (**) below

template<typename... Functors>
struct overloader : forwarder<Functors>...
{
  overloader(Functors&&... functors_a)
  : forwarder<Functors>(functors_a)...
  {} 
  using forwarder<Functor>::operator();...  //( **)

};

but  (**) is not correct in C++14.

The code after the #else part uses recursive inheritance and works with both compilers.

The question is if the code after #ifdef __clang__ is correct or if it is a BUG on clang?  

Vicente

[1] https://github.com/viboes/tags/issues/6#issuecomment-143444996

Larry Evans

unread,
Sep 30, 2015, 12:43:19 PM9/30/15
to std-dis...@isocpp.org
On 09/26/2015 11:27 AM, Vicente J. Botet Escriba wrote:
[snip]

> IMO it is missing something like the line (**) below
>
> template<typename... Functors>
> struct overloader : forwarder<Functors>...
> {
> overloader(Functors&&... functors_a)
> : forwarder<Functors>(functors_a)...
> {}
> using forwarder<Functor>::operator();... //( **)

This was proposed here:

https://groups.google.com/a/isocpp.org/d/msg/std-proposals/LoDJDCDDyH8/3Zv3tLppFzAJ


[snip]

Reply all
Reply to author
Forward
0 new messages