Skip to content

Commit 7c9594c

Browse files
committed
src: constrain MaybeStackBuffer::ToString and ToStringView to standard char types
On newer libc++ (shipped with macOS Xcode 16+), std::char_traits<T> 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<unsigned char> and std::basic_string_view<unsigned char>, 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<unsigned char> 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).
1 parent d9645d7 commit 7c9594c

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/util.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,8 +503,16 @@ class MaybeStackBuffer {
503503
free(buf_);
504504
}
505505

506-
inline std::basic_string<T> ToString() const { return {out(), length()}; }
507-
inline std::basic_string_view<T> ToStringView() const {
506+
inline std::basic_string<T> ToString() const
507+
requires(std::is_same_v<T, char> || std::is_same_v<T, wchar_t> ||
508+
std::is_same_v<T, char8_t> || std::is_same_v<T, char16_t> ||
509+
std::is_same_v<T, char32_t>) {
510+
return {out(), length()};
511+
}
512+
inline std::basic_string_view<T> ToStringView() const
513+
requires(std::is_same_v<T, char> || std::is_same_v<T, wchar_t> ||
514+
std::is_same_v<T, char8_t> || std::is_same_v<T, char16_t> ||
515+
std::is_same_v<T, char32_t>) {
508516
return {out(), length()};
509517
}
510518
// This can only be used if the buffer contains path data in UTF8

0 commit comments

Comments
 (0)