https://gcc.gnu.org/g:4e269ed1088e1d3235bca34846f2912e3ecb23b7
commit r15-11675-g4e269ed1088e1d3235bca34846f2912e3ecb23b7 Author: Jonathan Wakely <[email protected]> Date: Mon Oct 5 09:23:28 2026 +0100 libstdc++: do not zero stack buffer in std::bitset extraction The stack buffer used for the istream extraction operator does not need to be zero-filled before we write to it. To prevent that zeroing from happening automatically with -ftrivial-auto-var-init we can use the [[indeterminate]] attribute. For C++98 compatibility, __attribute__((uninitialized)) needs to be used instead. Also define a new variable for the array length which is never zero. This avoids a -Walloc-size warning in C++98 where the new-expression is not a discarded statement so the compiler sees `new _CharT[0]`: include/bitset:1717: warning: allocation of insufficient size '0' for type 'char' with size '1' [-Walloc-size] libstdc++-v3/ChangeLog: * include/std/bitset (operator>>): Define __array_len to ensure that the array size is never zero. Add uninitialized attribute to __buf. Reviewed-by: Tomasz KamiĆski <[email protected]> (cherry picked from commit 2763d2c224422f3a54b76659f3634c034089b9ed) Diff: --- libstdc++-v3/include/std/bitset | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libstdc++-v3/include/std/bitset b/libstdc++-v3/include/std/bitset index f9ec96fbb5dd..51beaa859d10 100644 --- a/libstdc++-v3/include/std/bitset +++ b/libstdc++-v3/include/std/bitset @@ -1606,13 +1606,14 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER typedef typename __istream_type::ios_base __ios_base; static const bool __use_local = _Nb * sizeof(_CharT) <= 256; + static const size_t __array_len = _Nb != 0 ? _Nb : 1; struct _Buffer { _Buffer() : _M_ptr(_M_local) { if _GLIBCXX17_CONSTEXPR (!__use_local) - _M_ptr = new _CharT[_Nb]; + _M_ptr = new _CharT[__array_len]; } ~_Buffer() @@ -1622,8 +1623,9 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER } _CharT* _M_ptr; - _CharT _M_local[__use_local && _Nb != 0 ? _Nb : 1]; - } __buf; + _CharT _M_local[__use_local ? __array_len : 1]; + }; + _Buffer __buf __attribute__((__uninitialized__)); _CharT* __ptr = __buf._M_ptr;
