[PATCH] D135238: [clang] adds copy-constructible type-trait builtins

Nikolas Klauser via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 6 06:57:43 PDT 2022


philnik added a comment.

TBH I don't think adding these builtins is worth the extra maintenance cost. libc++'s implementation is already really simple, and actually //uses// `__is_constructible`, contrary to the statement in the summary. This is the whole implementation currently:

  template <class _Tp>
  struct _LIBCPP_TEMPLATE_VIS is_copy_constructible
      : public integral_constant<
            bool,
            __is_constructible(_Tp, __add_lvalue_reference_t<typename add_const<_Tp>::type>)> {};
  
  #if _LIBCPP_STD_VER > 14
  template <class _Tp>
  inline constexpr bool is_copy_constructible_v = is_copy_constructible<_Tp>::value;
  #endif

I don't think adding an extra `#if __has_builtin(...)` is worth it in this case, since we already use builtins for most of it. IMO the effort would be better spent adding a builtin for `add_const`; that would probably make the implementation about as efficient as adding a builtin specifically for `is_copy_constructible`. It would effectively just be `__is_constructible(_Tp, __add_lvalue_reference(__add_const(_Tp)))`. The `trivially` and `nothrow` versions look very similar, just with `__is_trivially_constructible` and `__is_nothrow_constructible` respectively.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D135238/new/

https://reviews.llvm.org/D135238



More information about the cfe-commits mailing list