From 9f3892dcec6e65cb28198b438ecdf61de6508b68 Mon Sep 17 00:00:00 2001 From: om-ghante Date: Mon, 30 Mar 2026 19:13:13 +0530 Subject: [PATCH] src: fix MaybeStackBuffer char_traits deprecation warning 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 their return types reference std::basic_string and std::basic_string_view, even though these methods are never actually called for those types. Convert ToString() and ToStringView() into member function templates with a constrained default template parameter, so the return type is only instantiated when the function is actually called. Extract the type list into a reusable standard_char_type concept. --- src/util.h | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/util.h b/src/util.h index 873a204f9cd794..922ae4b1966f75 100644 --- a/src/util.h +++ b/src/util.h @@ -390,6 +390,14 @@ 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 +511,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