[libcxx-commits] [libcxx] [libc++] Verifies std::forward_like's mandates clause. (PR #127318)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Wed Mar 26 17:53:10 PDT 2025


https://github.com/ldionne approved this pull request.

I think Nikolas' point is that if we implement a _Mandates_ as SFINAE, that's something that users can rely on to disable their own overloads. But if we switched to a `static_assert` instead, their code would start failing with a hard error. So in that way, implementing a _Mandates_ with a `static_assert` is stricter and "closer to the strict interpretation of the spec".

I would also rather implement this _Mandates_ as a `static_assert` if we can: for example we could add the following to the body of `__forward_like`:

```
static_assert(__is_referenceable_v<_Tp>, "some nice message");
```

But in practice, the signature of `forward_like` itself means that a non-referenceable type is always going to result in `forward_like` SFINAE-ing away. So I don't see a way to improve the situation and even adding a `static_assert` to the body of the function wouldn't help, since we'd never reach it.

In light of that, this patch LGTM.

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


More information about the libcxx-commits mailing list