[libcxx-commits] [PATCH] D145376: [libc++] add declval failure assertion for instantiation

A. Jiang via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Mar 6 18:07:45 PST 2023


frederick-vs-ja added inline comments.


================
Comment at: libcxx/include/__utility/declval.h:29
 
-template <class _Tp>
-decltype(std::__declval<_Tp>(0)) declval() _NOEXCEPT;
+template <class _Tp, bool _False = false>
+_LIBCPP_HIDE_FROM_ABI decltype(std::__declval<_Tp>(0)) declval() _NOEXCEPT {
----------------
I think it's better not to modify the template head.
Doesn't libc++ have a concentrated `__dependent_false`? If so, I think we can still use `!__is_same(_Tp, _Tp)` in `static_assert`.


================
Comment at: libcxx/include/__utility/declval.h:30
+template <class _Tp, bool _False = false>
+_LIBCPP_HIDE_FROM_ABI decltype(std::__declval<_Tp>(0)) declval() _NOEXCEPT {
+  static_assert(_False, "Calling declval is ill-formed, see [declval]/2.");
----------------
The return type is... cursed for //cv// `void`.

It seems that `decltype(std::declval<const void>)` should be `const void()` (until C++17) / `const void() noexcept` (since C++17) (same for `volatile void` and `const volatile void`), but the cv-qualifiers are dropped in `decltype(std::__declval<_Tp>(0))`.


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

https://reviews.llvm.org/D145376



More information about the libcxx-commits mailing list