This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/58569] Compilation error when a class contains multiple std::function


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58569

--- Comment #11 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Further reduced (clang gives the same error for this version):

struct false_type { enum { value=0 }; };
struct true_type { enum { value=1 }; };

template<typename T>
  struct add_rvalue_reference {
    using type = T&&;
  };

template<typename _Tp>
  typename add_rvalue_reference<_Tp>::type declval() noexcept;

template<typename _From, typename _To>
  class __is_convertible_helper
  {
     template<typename _To1>
      static void __test_aux(_To1);

    template<typename _From1, typename _To1,
             typename = decltype(__test_aux<_To1>(declval<_From1>()))>
      static true_type
      __test(int);

    template<typename, typename>
      static false_type
      __test(...);

  public:
    typedef decltype(__test<_From, _To>(0)) type;
  };

/// is_convertible
template<typename _From, typename _To>
  struct is_convertible
  : public __is_convertible_helper<_From, _To>::type
  { };

template<bool B> struct enable_if { typedef void type; };
template<typename T> struct enable_if<false, T> { };

template<typename _Functor>
  inline _Functor&
  __callable_functor(_Functor& __f)
  { return __f; }

template<typename S> struct Function;

template<typename R, typename... A>
struct Function<R(A...)>
{
  template<typename F>
    using Invoke = decltype(__callable_functor(declval<F&>())
                            (declval<A>()...) );

  template<typename CallRes, typename Res1>
    struct CheckResult
    : is_convertible<CallRes, Res1> { };

  // template<typename CR> struct CheckResult<CR, CR> : true_type { };

  template<typename F>
    using Callable = CheckResult<Invoke<F>, R>;

  template<typename Cond>
    using Requires = typename enable_if<Cond::value>::type;

  template<typename F, typename = Requires<Callable<F>>>
    Function(F);

  Function();

  R operator()(A...) const;
};

struct foo {
  Function<foo (int)> x;
  Function<foo ()> y;
};

int main() {
  foo a;
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]