In a testdir of all of gnulib, built with GCC 15 and CFLAGS="-O2 -g -Wsystem-headers" CXXFLAGS="-O2 -g -Wsystem-headers", I see the following -Wsystem-headers warnings:
../gllib/string.h:754:20: warning: declaration of 'void* memcpy(void*, const void*, size_t)' has a different exception specifier ../gllib/string.h:757:20: warning: declaration of 'void* memccpy(void*, const void*, int, size_t)' has a different exception specifier ../gllib/string.h:760:20: warning: declaration of 'void* memmove(void*, const void*, size_t)' has a different exception specifier ../gllib/string.h:763:20: warning: declaration of 'char* strncpy(char*, const char*, size_t)' has a different exception specifier ../gllib/string.h:766:20: warning: declaration of 'char* strndup(const char*, size_t)' has a different exception specifier ../gllib/string.h:768:20: warning: declaration of 'char* strncat(char*, const char*, size_t)' has a different exception specifier ../gllib/string.h:770:18: warning: declaration of 'int memcmp(const void*, const void*, size_t)' has a different exception specifier ../gllib/string.h:773:18: warning: declaration of 'int strncmp(const char*, const char*, size_t)' has a different exception specifier ../gllib/string.h:782:20: warning: declaration of 'void* memset(void*, int, size_t)' has a different exception specifier ../gllib/string.h:1326:1: warning: declaration of 'char* strndup(const char*, size_t) noexcept' has a different exception specifier ../gllib/wchar.h:820:23: warning: declaration of 'wchar_t* wmemcpy(wchar_t*, const wchar_t*, size_t)' has a different exception specifier ../gllib/wchar.h:823:23: warning: declaration of 'wchar_t* wmemmove(wchar_t*, const wchar_t*, size_t)' has a different exception specifier ../gllib/wchar.h:826:23: warning: declaration of 'wchar_t* wcsncpy(wchar_t*, const wchar_t*, size_t)' has a different exception specifier ../gllib/wchar.h:829:23: warning: declaration of 'wchar_t* wcsncat(wchar_t*, const wchar_t*, size_t)' has a different exception specifier ../gllib/wchar.h:831:18: warning: declaration of 'int wmemcmp(const wchar_t*, const wchar_t*, size_t)' has a different exception specifier ../gllib/wchar.h:834:18: warning: declaration of 'int wcsncmp(const wchar_t*, const wchar_t*, size_t)' has a different exception specifier ../gllib/wchar.h:841:23: warning: declaration of 'wchar_t* wmemset(wchar_t*, wchar_t, size_t)' has a different exception specifier This patch fixes them. 2025-05-11 Bruno Haible <br...@clisp.org> string-h, wchar-h: Fix some g++ -Wsystem-headers warnings. * lib/string.in.h (memcpy, memccpy, memmove, strncpy, strndup, strncat, memcmp, strncmp, memset): On glibc systems, declare with _GL_ATTRIBUTE_NOTHROW. * lib/wchar.in.h (wmemcpy, wmemmove, wcsncpy, wcsncat, wmemcmp, wcsncmp, wmemset): Likewise. diff --git a/lib/string.in.h b/lib/string.in.h index e764221168..e3d94b76c1 100644 --- a/lib/string.in.h +++ b/lib/string.in.h @@ -215,25 +215,49 @@ _GL_EXTERN_C void free (void *); /* Declarations for ISO C N3322. */ #if defined __GNUC__ && __GNUC__ >= 15 && !defined __clang__ _GL_EXTERN_C void *memcpy (void *__dest, const void *__src, size_t __n) +# if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2 + _GL_ATTRIBUTE_NOTHROW +# endif _GL_ATTRIBUTE_NONNULL_IF_NONZERO (1, 3) _GL_ATTRIBUTE_NONNULL_IF_NONZERO (2, 3); _GL_EXTERN_C void *memccpy (void *__dest, const void *__src, int __c, size_t __n) +# if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2 + _GL_ATTRIBUTE_NOTHROW +# endif _GL_ATTRIBUTE_NONNULL_IF_NONZERO (1, 4) _GL_ATTRIBUTE_NONNULL_IF_NONZERO (2, 4); _GL_EXTERN_C void *memmove (void *__dest, const void *__src, size_t __n) +# if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2 + _GL_ATTRIBUTE_NOTHROW +# endif _GL_ATTRIBUTE_NONNULL_IF_NONZERO (1, 3) _GL_ATTRIBUTE_NONNULL_IF_NONZERO (2, 3); _GL_EXTERN_C char *strncpy (char *__dest, const char *__src, size_t __n) +# if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2 + _GL_ATTRIBUTE_NOTHROW +# endif _GL_ATTRIBUTE_NONNULL_IF_NONZERO (1, 3) _GL_ATTRIBUTE_NONNULL_IF_NONZERO (2, 3); _GL_EXTERN_C char *strndup (const char *__s, size_t __n) +# if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2 + _GL_ATTRIBUTE_NOTHROW +# endif _GL_ATTRIBUTE_NONNULL_IF_NONZERO (1, 2); _GL_EXTERN_C char *strncat (char *__dest, const char *__src, size_t __n) +# if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2 + _GL_ATTRIBUTE_NOTHROW +# endif _GL_ARG_NONNULL ((1)) _GL_ATTRIBUTE_NONNULL_IF_NONZERO (2, 3); _GL_EXTERN_C int memcmp (const void *__s1, const void *__s2, size_t __n) +# if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2 + _GL_ATTRIBUTE_NOTHROW +# endif _GL_ATTRIBUTE_NONNULL_IF_NONZERO (1, 3) _GL_ATTRIBUTE_NONNULL_IF_NONZERO (2, 3); _GL_EXTERN_C int strncmp (const char *__s1, const char *__s2, size_t __n) +# if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2 + _GL_ATTRIBUTE_NOTHROW +# endif _GL_ATTRIBUTE_NONNULL_IF_NONZERO (1, 3) _GL_ATTRIBUTE_NONNULL_IF_NONZERO (2, 3); # ifndef __cplusplus @@ -243,6 +267,9 @@ _GL_EXTERN_C void *memrchr (const void *__s, int __c, size_t __n) _GL_ATTRIBUTE_NONNULL_IF_NONZERO (1, 3); # endif _GL_EXTERN_C void *memset (void *__s, int __c, size_t __n) +# if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2 + _GL_ATTRIBUTE_NOTHROW +# endif _GL_ATTRIBUTE_NONNULL_IF_NONZERO (1, 3); _GL_EXTERN_C void *memset_explicit (void *__s, int __c, size_t __n) _GL_ATTRIBUTE_NONNULL_IF_NONZERO (1, 3); diff --git a/lib/wchar.in.h b/lib/wchar.in.h index 8836ed10e6..a6c52eb9c6 100644 --- a/lib/wchar.in.h +++ b/lib/wchar.in.h @@ -281,20 +281,38 @@ _GL_EXTERN_C void free (void *); /* Declarations for ISO C N3322. */ #if defined __GNUC__ && __GNUC__ >= 15 && !defined __clang__ _GL_EXTERN_C wchar_t *wmemcpy (wchar_t *__dest, const wchar_t *__src, size_t __n) +# if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2 + _GL_ATTRIBUTE_NOTHROW +# endif _GL_ATTRIBUTE_NONNULL_IF_NONZERO (1, 3) _GL_ATTRIBUTE_NONNULL_IF_NONZERO (2, 3); _GL_EXTERN_C wchar_t *wmemmove (wchar_t *__dest, const wchar_t *__src, size_t __n) +# if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2 + _GL_ATTRIBUTE_NOTHROW +# endif _GL_ATTRIBUTE_NONNULL_IF_NONZERO (1, 3) _GL_ATTRIBUTE_NONNULL_IF_NONZERO (2, 3); _GL_EXTERN_C wchar_t *wcsncpy (wchar_t *__dest, const wchar_t *__src, size_t __n) +# if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2 + _GL_ATTRIBUTE_NOTHROW +# endif _GL_ATTRIBUTE_NONNULL_IF_NONZERO (1, 3) _GL_ATTRIBUTE_NONNULL_IF_NONZERO (2, 3); _GL_EXTERN_C wchar_t *wcsncat (wchar_t *__dest, const wchar_t *__src, size_t __n) +# if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2 + _GL_ATTRIBUTE_NOTHROW +# endif _GL_ARG_NONNULL ((1)) _GL_ATTRIBUTE_NONNULL_IF_NONZERO (2, 3); _GL_EXTERN_C int wmemcmp (const wchar_t *__s1, const wchar_t *__s2, size_t __n) +# if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2 + _GL_ATTRIBUTE_NOTHROW +# endif _GL_ATTRIBUTE_NONNULL_IF_NONZERO (1, 3) _GL_ATTRIBUTE_NONNULL_IF_NONZERO (2, 3); _GL_EXTERN_C int wcsncmp (const wchar_t *__s1, const wchar_t *__s2, size_t __n) +# if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2 + _GL_ATTRIBUTE_NOTHROW +# endif _GL_ATTRIBUTE_NONNULL_IF_NONZERO (1, 3) _GL_ATTRIBUTE_NONNULL_IF_NONZERO (2, 3); # ifndef __cplusplus @@ -302,6 +320,9 @@ _GL_EXTERN_C wchar_t *wmemchr (const wchar_t *__s, wchar_t __wc, size_t __n) _GL_ATTRIBUTE_NONNULL_IF_NONZERO (1, 3); # endif _GL_EXTERN_C wchar_t *wmemset (wchar_t *__s, wchar_t __wc, size_t __n) +# if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2 + _GL_ATTRIBUTE_NOTHROW +# endif _GL_ATTRIBUTE_NONNULL_IF_NONZERO (1, 3); #endif