Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit da52b09

Browse filesBrowse files
omghanteaduh95
authored andcommitted
src: fix MaybeStackBuffer char_traits deprecation warning
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 their return types reference std::basic_string<unsigned char> and std::basic_string_view<unsigned char>, 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. PR-URL: #62507 Refs: #62506 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent ae87597 commit da52b09
Copy full SHA for da52b09

1 file changed

+14-2Lines changed: 14 additions & 2 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/util.h‎

Copy file name to clipboardExpand all lines: src/util.h
+14-2Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,14 @@ constexpr size_t strsize(const T (&)[N]) {
390390
return N - 1;
391391
}
392392

393+
// A type that has a valid std::char_traits specialization, as required by
394+
// std::basic_string and std::basic_string_view.
395+
template <typename T>
396+
concept standard_char_type =
397+
std::is_same_v<T, char> || std::is_same_v<T, wchar_t> ||
398+
std::is_same_v<T, char8_t> || std::is_same_v<T, char16_t> ||
399+
std::is_same_v<T, char32_t>;
400+
393401
// Allocates an array of member type T. For up to kStackStorageSize items,
394402
// the stack is used, otherwise malloc().
395403
template <typename T, size_t kStackStorageSize = 1024>
@@ -503,8 +511,12 @@ class MaybeStackBuffer {
503511
free(buf_);
504512
}
505513

506-
inline std::basic_string<T> ToString() const { return {out(), length()}; }
507-
inline std::basic_string_view<T> ToStringView() const {
514+
template <standard_char_type U = T>
515+
inline std::basic_string<U> ToString() const {
516+
return {out(), length()};
517+
}
518+
template <standard_char_type U = T>
519+
inline std::basic_string_view<U> ToStringView() const {
508520
return {out(), length()};
509521
}
510522
// This can only be used if the buffer contains path data in UTF8

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.