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.

libstdc++-v3/ChangeLog:

        * include/bits/stdexcept_throwfwd.h (__throw_out_of_range_fmt):
        Do not use __format__ attribute for C++98.
---

Tested x86_64-linux.

 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__));
-- 
2.55.0

Reply via email to