src: constrain MaybeStackBuffer::ToString and ToStringView to standard char types#62507
src: constrain MaybeStackBuffer::ToString and ToStringView to standard char types#62507omghante wants to merge 1 commit intonodejs:mainfrom
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.81% 89.81% -0.01%
==========================================
Files 699 699
Lines 216235 216466 +231
Branches 41336 41389 +53
==========================================
+ Hits 194216 194412 +196
- Misses 14129 14143 +14
- Partials 7890 7911 +21
🚀 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
2951d47 to
9f3892d
Compare
Commit Queue failed- Loading data for nodejs/node/pull/62507 ✔ Done loading data for nodejs/node/pull/62507 ----------------------------------- PR info ------------------------------------ Title src: constrain MaybeStackBuffer::ToString and ToStringView to standard char types (#62507) ⚠ Could not retrieve the email or name of the PR author's from user's GitHub profile! Branch omghante:fix/constrain-maybstackbuffer-tostring-char-traits -> nodejs:main Labels c++, author ready, needs-ci Commits 1 - src: fix MaybeStackBuffer char_traits deprecation warning Committers 1 - om-ghante <mr.omghante1@gmail.com> PR-URL: https://github.com/nodejs/node/pull/62507 Refs: https://github.com/nodejs/node/issues/62506 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Anna Henningsen <anna@addaleax.net> ------------------------------ Generated metadata ------------------------------ PR-URL: https://github.com/nodejs/node/pull/62507 Refs: https://github.com/nodejs/node/issues/62506 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Anna Henningsen <anna@addaleax.net> -------------------------------------------------------------------------------- ℹ This PR was created on Mon, 30 Mar 2026 13:45:22 GMT ✔ Approvals: 3 ✔ - Yagiz Nizipli (@anonrig) (TSC): https://github.com/nodejs/node/pull/62507#pullrequestreview-4051985736 ✔ - Tobias Nießen (@tniessen) (TSC): https://github.com/nodejs/node/pull/62507#pullrequestreview-4114804604 ✔ - Anna Henningsen (@addaleax): https://github.com/nodejs/node/pull/62507#pullrequestreview-4141239569 ✘ 1 GitHub CI job(s) failed: ✘ - x86_64-darwin: with shared libraries: FAILURE (https://github.com/nodejs/node/actions/runs/23905606841/job/69714214012) ℹ Last Full PR CI on 2026-04-16T12:45:57Z: https://ci.nodejs.org/job/node-test-pull-request/72722/ - Querying data for job/node-test-pull-request/72722/ ✔ Build data downloaded ✔ Last Jenkins CI successful -------------------------------------------------------------------------------- ✔ Aborted `git node land` session in /home/runner/work/node/node/.ncuhttps://github.com/nodejs/node/actions/runs/24676220710 |
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>
|
Landed in e02087c |
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