https://gcc.gnu.org/g:787d1973b7e5fef891ad2ba66fe6489ff6fcbafd
commit r17-4897-g787d1973b7e5fef891ad2ba66fe6489ff6fcbafd Author: Jonathan Wakely <[email protected]> Date: Mon Oct 5 10:47:05 2026 +0100 libstdc++: Only use format gnu_printf attribute for C++11 and later This avoids pedantic warnings in C++98 caused by %zu in the format strings passed to the __throw_out_of_range_fmt function: include/bitset:845: warning: ISO C++98 does not support the 'z' gnu_printf length modifier [-Wformat=] The definition of the function is in src/c++11/functexcept.cc and compiled using -std=gnu++11 so the %zu format works fine. We just can't tell C++98 translation units that it works, so suppress the attribute in C++98. We could instead use diagnostic pragmas (conditional on C++ language dialect) at every call site, but that would add seven lines to every affected call site instead of just making the attribute conditional in one place. And it would be functionally equivalent to just suppressing the attribute anyway. libstdc++-v3/ChangeLog: * include/bits/stdexcept_throwfwd.h (__throw_out_of_range_fmt): Do not use __format__ attribute for C++98. Reviewed-by: Tomasz KamiĆski <[email protected]> Diff: --- libstdc++-v3/include/bits/stdexcept_throwfwd.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/include/bits/stdexcept_throwfwd.h b/libstdc++-v3/include/bits/stdexcept_throwfwd.h index 9b0aad3571d3..3980a60bd5c3 100644 --- a/libstdc++-v3/include/bits/stdexcept_throwfwd.h +++ b/libstdc++-v3/include/bits/stdexcept_throwfwd.h @@ -81,9 +81,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION void __throw_out_of_range(const char*) __attribute__((__noreturn__,__cold__)); +#if __cplusplus >= 201103L + // C++98 does not support %zu which is used in most calls to this function. + [[__gnu__::__format__(__gnu_printf__, 1, 2)]] +#endif void __throw_out_of_range_fmt(const char*, ...) - __attribute__((__noreturn__,__cold__,__format__(__gnu_printf__, 1, 2))); + __attribute__((__noreturn__,__cold__)); void __throw_runtime_error(const char*) __attribute__((__noreturn__,__cold__));
