Fix C++17 compilation error on FreeBSD GCC 13.3

Remove custom deduction guides for std::unique_ptr in C++17 mode.

Issue: FreeBSD GCC 13.3 correctly rejects adding deduction guides
to namespace std, which violates C++ standard [namespace.std]:
"The behavior of a C++ program is undefined if it adds declarations
or definitions to namespace std or to a namespace within namespace std."

Root cause: The code attempted to add custom deduction guides for
std::unique_ptr in namespace std when compiling in C++17 mode.
This is not allowed by the C++ standard.

Solution: Remove the custom deduction guides for C++17 and later,
as the C++17 standard library already provides deduction guides
for std::unique_ptr (added in C++17 via P0433R2).

The custom deduction guide wrappers in the else branch (for C++14
and earlier) are kept as they provide helper functions, not actual
deduction guides in namespace std.

Tested-on: FreeBSD 15 with GCC 13.3
Fixes: Compilation error 'deduction guide must be declared in the
same scope as template std::unique_ptr'
This commit is contained in:
木头云 2025-12-06 06:13:58 +00:00
parent 543672b39d
commit a82e3faf63

View File

@ -72,15 +72,9 @@
#if __cplusplus >= 201703L #if __cplusplus >= 201703L
namespace std {
// deduction guides for std::unique_ptr // C++17 and later: std library already provides deduction guides
template <typename T> // No need to add custom ones, just use the standard ones directly
unique_ptr(T* p) -> unique_ptr<T>;
template <typename T, typename D>
unique_ptr(T* p, D&& d) -> unique_ptr<T, std::decay_t<D>>;
} // namespace std
namespace ipc { namespace ipc {
namespace detail { namespace detail {