From 8eb1cad1f7831fc0c2b0752f6c490cb3f6d715d4 Mon Sep 17 00:00:00 2001 From: om-ghante Date: Mon, 30 Mar 2026 19:13:13 +0530 Subject: [PATCH] src: constrain MaybeStackBuffer::ToString and ToStringView to standard char types On newer libc++ (shipped with macOS Xcode 16+), std::char_traits for T not equal to char, wchar_t, char8_t, char16_t, or char32_t is deprecated and will be removed in a future release. When MaybeStackBuffer is instantiated with unsigned char or uint8_t (e.g. in test/cctest/test_util.cc), the ToString() and ToStringView() methods trigger this deprecation warning because they reference std::basic_string and std::basic_string_view, even though these methods are never actually called for those types. Add C++20 requires clauses to constrain ToString() and ToStringView() to only be available for standard character types, preventing the deprecated std::char_traits from being instantiated. This is consistent with the existing use of C++20 concepts elsewhere in the same file (e.g. the is_callable concept). --- src/util.h | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/util.h b/src/util.h index 873a204f9cd794..a56f289b9af802 100644 --- a/src/util.h +++ b/src/util.h @@ -390,6 +390,15 @@ constexpr size_t strsize(const T (&)[N]) { return N - 1; } +// A type that has a valid std::char_traits specialization, as required by +// std::basic_string and std::basic_string_view. +template +concept standard_char_type = std::is_same_v || + std::is_same_v || + std::is_same_v || + std::is_same_v || + std::is_same_v; + // Allocates an array of member type T. For up to kStackStorageSize items, // the stack is used, otherwise malloc(). template @@ -503,8 +512,12 @@ class MaybeStackBuffer { free(buf_); } - inline std::basic_string ToString() const { return {out(), length()}; } - inline std::basic_string_view ToStringView() const { + template + inline std::basic_string ToString() const { + return {out(), length()}; + } + template + inline std::basic_string_view ToStringView() const { return {out(), length()}; } // This can only be used if the buffer contains path data in UTF8