[PATCH] D7573: [libc++] Fix PR20084 - std::is_function<void() const> failed.

Eric Niebler via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 11 15:18:25 PDT 2017

eric_niebler added a comment.

I just ran into this problem while trying to get range-v3 working on clang-3.6. This `is_function` implementation //probably// instantiates fewer templates than the version currently shipping with libc++. Disclaimer: I haven't tested it exhaustively yet.

  template<int I>
  struct priority_tag
      : priority_tag<I - 1>
  struct priority_tag<0>
  // Function types here:
  template<typename T>
  char (&is_function_impl_(priority_tag<0>))[1];
  // Array types here:
  template<typename T, typename = decltype((*(T*)0)[0])>
  char (&is_function_impl_(priority_tag<1>))[2];
  // Anything that can be returned from a function here (including
  // void and reference types):
  template<typename T, typename = T(*)()>
  char (&is_function_impl_(priority_tag<2>))[3];
  // Classes and unions (including abstract types) here:
  template<typename T, typename = int T::*>
  char (&is_function_impl_(priority_tag<3>))[4];
  template <typename T>
  struct is_function
      : integral_constant<bool, sizeof(is_function_impl_<T>(priority_tag<3>{})) == 1>


More information about the cfe-commits mailing list