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

A. Jiang via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Wed Mar 8 18:11:04 PST 2023


frederick-vs-ja added a comment.

In D145376#4176228 <https://reviews.llvm.org/D145376#4176228>, @EricWF wrote:

> This change is not correct and cannot proceed.
>
> It changes the meaning of this code:
>
>   template <class T, class U, class = U[std::declval<T>()]>
>   constexpr bool xxx(int) { return true; }
>   
>   template <class T, class U>
>   constexpr bool xxx(long) { return false; }
>   
>   constexpr bool y = xxx<long long, int>(0);
>
> declval has been constructed very carefully to performant, and correct in all the weird cases where Clang will try to eagerly instantiate something (Ex. when it tries to check for C++11 narrowing when evaluating constant expressions).
> Please be cautious when modifying weird things like declval.

I think this is a bug of the Clang frontend.
P0859R0 <https://wg21.link/p0859r0> clarified when a function template or a defaulted function should be instantiated due to constant evaluation. `std::declval` is never a constexpr function, so it is never needed for constant evaluation, and the (ill-formed) //type-id// `U[std::declval<T>()]` should result in substitution failure without instantiating `std::declval<T>`.


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

https://reviews.llvm.org/D145376



More information about the libcxx-commits mailing list