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

Christopher Di Bella via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Fri Mar 10 12:22:52 PST 2023


cjdb added inline comments.


================
Comment at: libcxx/include/__utility/declval.h:31
+_LIBCPP_HIDE_FROM_ABI decltype(std::__declval<_Tp>(0)) declval() _NOEXCEPT {
+  static_assert(!__is_same(_Tp, _Tp), "Calling declval is ill-formed, see [declval]/2.");
+}
----------------
Can this please be a more user-friendly diagnostic? Saying `"This is ill-formed. Read this [standarese]"` doesn't help the user understand what is going on or how to fix it. Something along the lines of this will be more in line with the Clang effort to improve diagnostics (something that hasn't been broached with libc++ yet, but here's a good place to try a new diagnostic).
```
static_assert(
  always_false<T>,
  "`std::declval` can only be used in an unevaluated context. It's likely that our current usage is trying to extract a value from the function.");
```


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

https://reviews.llvm.org/D145376



More information about the libcxx-commits mailing list