src: constrain MaybeStackBuffer::ToString and ToStringView to standard char types#62507
Conversation
ecb3efb to
7c9594c
Compare
|
Have you tried your changes? I applied the patch and still see a deprecation warning. |
b42db3d to
8eb1cad
Compare
Yes, I have checked my updated changes and the deprecation warning is now gone. The issue with the first patch was that |
|
Thanks. I confirm there is no warning anymore with the latest push. I defer to @nodejs/cpp-reviewers for the code review. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #62507 +/- ##
==========================================
- Coverage 89.69% 89.69% -0.01%
==========================================
Files 692 695 +3
Lines 214039 214214 +175
Branches 41064 41026 -38
==========================================
+ Hits 191985 192140 +155
- Misses 14134 14155 +21
+ Partials 7920 7919 -1
🚀 New features to boost your workflow:
|
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.
8eb1cad to
9f3892d
Compare
On newer libc++ (shipped with macOS Xcode 16+),
std::char_traits<T>forTnotequal to
char,wchar_t,char8_t,char16_t, orchar32_tis deprecated andwill be removed in a future release.
When the MaybeStackBuffer template is instantiated with
unsigned charoruint8_t(e.g., in test/cctest/test_util.cc), the compiler instantiates the declarations
for all member functions. The ToString() and ToStringView() methods historically returned
std::basic_string<T>andstd::basic_string_view<T>, which triggered thisdeprecation warning (
-Wdeprecated-declarations) during class instantiation becausethe return type references
std::char_traits<unsigned char>.Changes
This PR resolves the warning by:
standard_char_type.member function templates with a constrained default template parameter:
template <standard_char_type U = T>.By making these member function templates, the C++ compiler defers instantiating
the return type (
std::basic_string<U>) until the function is actually called. Sincethese methods are never actually called for
unsigned charoruint8_tvariantsin the Node.js codebase, the deprecated
std::char_traits<unsigned char>is neverevaluated or instantiated, completely bypassing the warning.
Refs: #62506