libstdc++: Improve SFINAE-friendliness of `std::unique_ptr<void>::operator*`.
Makes `std::unique_ptr<void>::operator*` SFINAE-friendly by adding a constraint for C++20 and adjusting the noexcept-specifier for older standards.
This commit implements LWG 4324, addressing the issue that std::unique_ptr<void>::operator* was not SFINAE-friendly due to the addition of a noexcept specifier in C++23 (LWG 2762). For C++20, a requires clause is added to constrain the function. For C++11/14/17, the noexcept specifier is adjusted to avoid ill-formed code. This change restores the original semantics, allowing code to check for the existence of the function in a SFINAE context without causing errors.
In Details
This commit addresses LWG 4324 by making unique_ptr<void>::operator* SFINAE-friendly. The noexcept specifier added by LWG 2762 caused issues when the pointer type couldn't be dereferenced. For C++20, a requires-clause is added. For C++11/14/17, _Nothrow_deref is used to adjust the noexcept specifier. The changes are in include/bits/unique_ptr.h, and a new test lwg4324.cc is added.
For Context
std::unique_ptr is a smart pointer that provides exclusive ownership of a dynamically allocated object. SFINAE (Substitution Failure Is Not An Error) is a C++ technique that allows the compiler to discard function overloads or template specializations if the substitution of template arguments results in invalid code. This commit ensures that code using SFINAE to check for the existence of std::unique_ptr<void>::operator* will not result in a hard error, which maintains compatibility and enables more flexible template metaprogramming.