[libcxx-commits] [libcxx] [libc++] Implement P2988R12: `std::optional<T&>` (PR #155202)
A. Jiang via libcxx-commits
libcxx-commits at lists.llvm.org
Sun Oct 26 21:28:38 PDT 2025
frederick-vs-ja wrote:
> Does that mean the reference implementation [beman::optional godbolt](https://godbolt.org/z/jb3eocK8j) is incorrect? It explicitly disallows such a use of `make_optional`, but at the same time, the draft standard mentions no such restriction.
I believe it's incorrect. There's nothing corresponding to that `static_assert(!std::is_reference_v<T>, "...");` in the proposal or the current standard wording. If we want to make it correct, an LWG issue is necessary.
> But at the same time, the proposal explicitly states that `make_optional` for the multi-argument overload should be ill-formed(?):
>
> > Adding a non-type template parameter as the first template parameter to the single argument make_optional
> > and mandating that the multi-argument version not request a reference type as the parameter, will diagnose
> > mistaken use of make_optional and preserve the existing behavior
If one provides more than one arguments to `std::make_optional<T&>`, the function call is automatically ill-formed due to the form of `optional<T&>`'s corresponding constructor. So we don't need to change the second or third `std::make_optional` overload.
https://github.com/llvm/llvm-project/pull/155202
More information about the libcxx-commits
mailing list