[libcxx-commits] [libcxx] [libc++] Use _If for conditional_t (PR #96193)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Wed Jun 26 09:07:39 PDT 2024


ldionne wrote:

I think this patch made us non-conforming. Minimal reproducer:

```c++
#include <type_traits>

template <class T, class = std::enable_if_t<
  !std::is_same_v<int, std::conditional_t<false, T, int>>
>>
void f() { }
```

Godbolt: https://godbolt.org/z/jGxn3nhbz

@philnik777 , can you please revert this patch and add a new test case to avoid regressing this?

The issue is that the Standard specifies:

```c++
template< bool B, class T, class F >
using conditional_t = typename conditional<B,T,F>::type;
```

The new implementation does not satisfy this "equivalent to" property because in @zmodem's use case, `typename conditional<false, Alloc, value_type>::type` as a whole would be a dependent type since `Alloc` is a template parameter of the function. However, with our new implementation of `conditional_t`, we disregard the first type entirely since the boolean is `false`, and this makes the instantiation of `conditional_t<B, T, F>` "less lazy" than it used to be, which is technically non-conforming.

https://github.com/llvm/llvm-project/pull/96193


More information about the libcxx-commits mailing list