These warnings in C++ mode ../gllib/malloc.h:615:1: warning: declaration of 'void* memalign(size_t, size_t)' has a different exception specifier [-Wsystem-headers] ../gllib/stdio.h:860:1: warning: declaration of 'FILE* fdopen(int, const char*)' has a different exception specifier [-Wsystem-headers] ../gllib/stdlib.h:800:1: warning: declaration of 'void* aligned_alloc(size_t, size_t)' has a different exception specifier [-Wsystem-headers] ../gllib/stdlib.h:858:1: warning: declaration of 'void* calloc(size_t, size_t)' has a different exception specifier [-Wsystem-headers] ../gllib/stdlib.h:894:1: warning: declaration of 'char* canonicalize_file_name(const char*)' has a different exception specifier [-Wsystem-headers] ../gllib/stdlib.h:1135:1: warning: declaration of 'void* malloc(size_t)' has a different exception specifier [-Wsystem-headers] ../gllib/stdlib.h:1858:1: warning: declaration of 'void* realloc(void*, size_t)' has a different exception specifier [-Wsystem-headers] ../gllib/string.h:1092:1: warning: declaration of 'char* strdup(const char*)' has a different exception specifier [-Wsystem-headers] ../gllib/string.h:1175:1: warning: declaration of 'char* strndup(const char*, size_t)' has a different exception specifier [-Wsystem-headers] ../gllib/sys/stat.h:1091:1: warning: declaration of 'mode_t getumask()' has a different exception specifier [-Wsystem-headers] ../gllib/wchar.h:1819:1: warning: declaration of 'wchar_t* wcsdup(const wchar_t*)' has a different exception specifier [-Wsystem-headers]
indicate that when redeclaring functions declared in system header files, we should better use the same exception specifier. For platforms without glibc, I wouldn't care about this warning, but for glibc platforms we can silence them: Where the glibc header files use __THROW, we can use _GL_ATTRIBUTE_NOTHROW. But note that in C++ mode, '__attribute__ ((__nothrow__))' is *not* equivalent to 'noexcept(true)' (or 'throw()' with older C++): $ cat foo.cc extern int __attribute__ ((__nothrow__)) foo (int x); extern int foo (int x) noexcept(true); $ g++ -S foo.cc foo.cc:2:12: error: declaration of ‘int foo(int) noexcept’ has a different exception specifier 2 | extern int foo (int x) noexcept(true); | ^~~ foo.cc:1:42: note: from previous declaration ‘int foo(int)’ 1 | extern int __attribute__ ((__nothrow__)) foo (int x); | ^~~ So, we have to change _GL_ATTRIBUTE_NOTHROW so that it becomes C++ aware. The patch below does this, in a way that it enables noexcept(true) under the same conditions than glibc for __THROW. 2023-09-04 Bruno Haible <br...@clisp.org> Fix some g++ warnings "has a different exception specifier". * m4/gnulib-common.m4 (gl_COMMON_BODY): Make _GL_ATTRIBUTE_NOTHROW effective in C++ mode. * lib/attribute.h (ATTRIBUTE_NOTHROW): Add a comment. * lib/malloc.in.h (_GL_ATTRIBUTE_NOTHROW): Provide fallback definition. (memalign): Invoke _GL_FUNCDECL_SYS with _GL_ATTRIBUTE_NOTHROW. * lib/stdio.in.h (_GL_ATTRIBUTE_NOTHROW): Provide fallback definition. (fdopen): Invoke _GL_FUNCDECL_SYS with _GL_ATTRIBUTE_NOTHROW. * lib/stdlib.in.h (_GL_ATTRIBUTE_NOTHROW): Provide fallback definition. (aligned_alloc, calloc, canonicalize_file_name, malloc, realloc): Invoke _GL_FUNCDECL_SYS with _GL_ATTRIBUTE_NOTHROW. * lib/string.in.h (_GL_ATTRIBUTE_NOTHROW): Provide fallback definition. (strdup, strndup): Invoke _GL_FUNCDECL_SYS with _GL_ATTRIBUTE_NOTHROW. * lib/sys_stat.in.h (_GL_ATTRIBUTE_NOTHROW): Provide fallback definition. (getumask): Invoke _GL_FUNCDECL_SYS with _GL_ATTRIBUTE_NOTHROW. * lib/wchar.in.h (_GL_ATTRIBUTE_NOTHROW): Provide fallback definition. (wcsdup): Invoke _GL_FUNCDECL_SYS with _GL_ATTRIBUTE_NOTHROW. diff --git a/m4/gnulib-common.m4 b/m4/gnulib-common.m4 index 2426eb6398..c372316135 100644 --- a/m4/gnulib-common.m4 +++ b/m4/gnulib-common.m4 @@ -1,4 +1,4 @@ -# gnulib-common.m4 serial 87 +# gnulib-common.m4 serial 88 dnl Copyright (C) 2007-2023 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -466,11 +466,25 @@ AC_DEFUN([gl_COMMON_BODY] /* _GL_ATTRIBUTE_NOTHROW declares that the function does not throw exceptions. */ /* Applies to: functions. */ +/* After a function's parameter list, this attribute must come first, before + other attributes. */ #ifndef _GL_ATTRIBUTE_NOTHROW -# if _GL_HAS_ATTRIBUTE (nothrow) && !defined __cplusplus -# define _GL_ATTRIBUTE_NOTHROW __attribute__ ((__nothrow__)) +# if defined __cplusplus +# if _GL_GNUC_PREREQ (2, 8) || __clang_major >= 4 +# if __cplusplus >= 201103L +# define _GL_ATTRIBUTE_NOTHROW noexcept (true) +# else +# define _GL_ATTRIBUTE_NOTHROW throw () +# endif +# else +# define _GL_ATTRIBUTE_NOTHROW +# endif # else -# define _GL_ATTRIBUTE_NOTHROW +# if _GL_HAS_ATTRIBUTE (nothrow) +# define _GL_ATTRIBUTE_NOTHROW __attribute__ ((__nothrow__)) +# else +# define _GL_ATTRIBUTE_NOTHROW +# endif # endif #endif diff --git a/lib/attribute.h b/lib/attribute.h index 9464fde0f3..e4e36092b0 100644 --- a/lib/attribute.h +++ b/lib/attribute.h @@ -182,6 +182,8 @@ /* The function does not throw exceptions. */ /* Applies to: functions. */ +/* After a function's parameter list, this attribute must come first, before + other attributes. */ #define ATTRIBUTE_NOTHROW _GL_ATTRIBUTE_NOTHROW /* Do not inline the function. */ diff --git a/lib/malloc.in.h b/lib/malloc.in.h index fe0e87c9c9..bfc749545e 100644 --- a/lib/malloc.in.h +++ b/lib/malloc.in.h @@ -46,7 +46,8 @@ #ifndef _@GUARD_PREFIX@_MALLOC_H #define _@GUARD_PREFIX@_MALLOC_H -/* This file uses _GL_ATTRIBUTE_DEALLOC, GNULIB_POSIXCHECK, HAVE_RAW_DECL_*. */ +/* This file uses _GL_ATTRIBUTE_DEALLOC, _GL_ATTRIBUTE_NOTHROW, + GNULIB_POSIXCHECK, HAVE_RAW_DECL_*. */ #if !_GL_CONFIG_H_INCLUDED #error "Please include config.h first." #endif @@ -59,6 +60,29 @@ /* Get size_t. */ #include <stddef.h> + +/* _GL_ATTRIBUTE_NOTHROW declares that the function does not throw exceptions. + */ +#ifndef _GL_ATTRIBUTE_NOTHROW +# if defined __cplusplus +# if (__GNUC__ + (__GNUC_MINOR__ >= 8) > 2) || __clang_major >= 4 +# if __cplusplus >= 201103L +# define _GL_ATTRIBUTE_NOTHROW noexcept (true) +# else +# define _GL_ATTRIBUTE_NOTHROW throw () +# endif +# else +# define _GL_ATTRIBUTE_NOTHROW +# endif +# else +# if (__GNUC__ + (__GNUC_MINOR__ >= 3) > 3) || defined __clang__ +# define _GL_ATTRIBUTE_NOTHROW __attribute__ ((__nothrow__)) +# else +# define _GL_ATTRIBUTE_NOTHROW +# endif +# endif +#endif + /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ /* The definition of _GL_WARN_ON_USE is copied here. */ @@ -127,6 +151,7 @@ _GL_CXXALIAS_RPL (memalign, void *, (size_t alignment, size_t size)); /* For -Wmismatched-dealloc: Associate memalign with free or rpl_free. */ _GL_FUNCDECL_SYS (memalign, void *, (size_t alignment, size_t size) + _GL_ATTRIBUTE_NOTHROW _GL_ATTRIBUTE_DEALLOC_FREE); # endif _GL_CXXALIAS_SYS (memalign, void *, (size_t alignment, size_t size)); @@ -140,6 +165,7 @@ _GL_CXXALIASWARN (memalign); /* For -Wmismatched-dealloc: Associate memalign with free or rpl_free. */ _GL_FUNCDECL_SYS (memalign, void *, (size_t alignment, size_t size) + _GL_ATTRIBUTE_NOTHROW _GL_ATTRIBUTE_DEALLOC_FREE); # endif # if defined GNULIB_POSIXCHECK diff --git a/lib/stdio.in.h b/lib/stdio.in.h index 6be12c0525..684c7a2826 100644 --- a/lib/stdio.in.h +++ b/lib/stdio.in.h @@ -58,7 +58,8 @@ #define _@GUARD_PREFIX@_STDIO_H /* This file uses _GL_ATTRIBUTE_DEALLOC, _GL_ATTRIBUTE_FORMAT, - _GL_ATTRIBUTE_MALLOC, GNULIB_POSIXCHECK, HAVE_RAW_DECL_*. */ + _GL_ATTRIBUTE_MALLOC, _GL_ATTRIBUTE_NOTHROW, GNULIB_POSIXCHECK, + HAVE_RAW_DECL_*. */ #if !_GL_CONFIG_H_INCLUDED #error "Please include config.h first." #endif @@ -143,6 +144,28 @@ # endif #endif +/* _GL_ATTRIBUTE_NOTHROW declares that the function does not throw exceptions. + */ +#ifndef _GL_ATTRIBUTE_NOTHROW +# if defined __cplusplus +# if (__GNUC__ + (__GNUC_MINOR__ >= 8) > 2) || __clang_major >= 4 +# if __cplusplus >= 201103L +# define _GL_ATTRIBUTE_NOTHROW noexcept (true) +# else +# define _GL_ATTRIBUTE_NOTHROW throw () +# endif +# else +# define _GL_ATTRIBUTE_NOTHROW +# endif +# else +# if (__GNUC__ + (__GNUC_MINOR__ >= 3) > 3) || defined __clang__ +# define _GL_ATTRIBUTE_NOTHROW __attribute__ ((__nothrow__)) +# else +# define _GL_ATTRIBUTE_NOTHROW +# endif +# endif +#endif + /* An __attribute__ __format__ specifier for a function that takes a format string and arguments, where the format string directives are the ones standardized by ISO C99 and POSIX. @@ -346,6 +369,7 @@ _GL_CXXALIAS_MDA (fdopen, FILE *, (int fd, const char *mode)); /* For -Wmismatched-dealloc: Associate fdopen with fclose or rpl_fclose. */ _GL_FUNCDECL_SYS (fdopen, FILE *, (int fd, const char *mode) + _GL_ATTRIBUTE_NOTHROW _GL_ARG_NONNULL ((2)) _GL_ATTRIBUTE_DEALLOC (fclose, 1) _GL_ATTRIBUTE_MALLOC); # endif @@ -357,6 +381,7 @@ _GL_CXXALIASWARN (fdopen); /* For -Wmismatched-dealloc: Associate fdopen with fclose or rpl_fclose. */ _GL_FUNCDECL_SYS (fdopen, FILE *, (int fd, const char *mode) + _GL_ATTRIBUTE_NOTHROW _GL_ARG_NONNULL ((2)) _GL_ATTRIBUTE_DEALLOC (fclose, 1) _GL_ATTRIBUTE_MALLOC); # endif diff --git a/lib/stdlib.in.h b/lib/stdlib.in.h index 1479a2b287..10bb811d9e 100644 --- a/lib/stdlib.in.h +++ b/lib/stdlib.in.h @@ -38,7 +38,8 @@ #define _@GUARD_PREFIX@_STDLIB_H /* This file uses _Noreturn, _GL_ATTRIBUTE_DEALLOC, _GL_ATTRIBUTE_MALLOC, - _GL_ATTRIBUTE_PURE, GNULIB_POSIXCHECK, HAVE_RAW_DECL_*. */ + _GL_ATTRIBUTE_NOTHROW, _GL_ATTRIBUTE_PURE, GNULIB_POSIXCHECK, + HAVE_RAW_DECL_*. */ #if !_GL_CONFIG_H_INCLUDED #error "Please include config.h first." #endif @@ -132,6 +133,28 @@ struct random_data # endif #endif +/* _GL_ATTRIBUTE_NOTHROW declares that the function does not throw exceptions. + */ +#ifndef _GL_ATTRIBUTE_NOTHROW +# if defined __cplusplus +# if (__GNUC__ + (__GNUC_MINOR__ >= 8) > 2) || __clang_major >= 4 +# if __cplusplus >= 201103L +# define _GL_ATTRIBUTE_NOTHROW noexcept (true) +# else +# define _GL_ATTRIBUTE_NOTHROW throw () +# endif +# else +# define _GL_ATTRIBUTE_NOTHROW +# endif +# else +# if (__GNUC__ + (__GNUC_MINOR__ >= 3) > 3) || defined __clang__ +# define _GL_ATTRIBUTE_NOTHROW __attribute__ ((__nothrow__)) +# else +# define _GL_ATTRIBUTE_NOTHROW +# endif +# endif +#endif + /* The __attribute__ feature is available in gcc versions 2.5 and later. The attribute __pure__ was added in gcc 2.96. */ #ifndef _GL_ATTRIBUTE_PURE @@ -236,6 +259,7 @@ _GL_CXXALIAS_RPL (aligned_alloc, void *, (size_t alignment, size_t size)); /* For -Wmismatched-dealloc: Associate aligned_alloc with free or rpl_free. */ _GL_FUNCDECL_SYS (aligned_alloc, void *, (size_t alignment, size_t size) + _GL_ATTRIBUTE_NOTHROW _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE); # endif _GL_CXXALIAS_SYS (aligned_alloc, void *, (size_t alignment, size_t size)); @@ -249,6 +273,7 @@ _GL_CXXALIASWARN (aligned_alloc); /* For -Wmismatched-dealloc: Associate aligned_alloc with free or rpl_free. */ _GL_FUNCDECL_SYS (aligned_alloc, void *, (size_t alignment, size_t size) + _GL_ATTRIBUTE_NOTHROW _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE); # endif # if defined GNULIB_POSIXCHECK @@ -294,6 +319,7 @@ _GL_CXXALIAS_RPL (calloc, void *, (size_t nmemb, size_t size)); /* For -Wmismatched-dealloc: Associate calloc with free or rpl_free. */ _GL_FUNCDECL_SYS (calloc, void *, (size_t nmemb, size_t size) + _GL_ATTRIBUTE_NOTHROW _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE); # endif _GL_CXXALIAS_SYS (calloc, void *, (size_t nmemb, size_t size)); @@ -306,6 +332,7 @@ _GL_CXXALIASWARN (calloc); /* For -Wmismatched-dealloc: Associate calloc with free or rpl_free. */ _GL_FUNCDECL_SYS (calloc, void *, (size_t nmemb, size_t size) + _GL_ATTRIBUTE_NOTHROW _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE); # endif # if defined GNULIB_POSIXCHECK @@ -330,6 +357,7 @@ _GL_CXXALIAS_RPL (canonicalize_file_name, char *, (const char *name)); # if !@HAVE_CANONICALIZE_FILE_NAME@ || __GNUC__ >= 11 _GL_FUNCDECL_SYS (canonicalize_file_name, char *, (const char *name) + _GL_ATTRIBUTE_NOTHROW _GL_ARG_NONNULL ((1)) _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE); # endif @@ -346,6 +374,7 @@ _GL_CXXALIASWARN (canonicalize_file_name); rpl_free. */ _GL_FUNCDECL_SYS (canonicalize_file_name, char *, (const char *name) + _GL_ATTRIBUTE_NOTHROW _GL_ARG_NONNULL ((1)) _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE); # endif @@ -571,6 +600,7 @@ _GL_CXXALIAS_RPL (malloc, void *, (size_t size)); /* For -Wmismatched-dealloc: Associate malloc with free or rpl_free. */ _GL_FUNCDECL_SYS (malloc, void *, (size_t size) + _GL_ATTRIBUTE_NOTHROW _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE); # endif _GL_CXXALIAS_SYS (malloc, void *, (size_t size)); @@ -583,6 +613,7 @@ _GL_CXXALIASWARN (malloc); /* For -Wmismatched-dealloc: Associate malloc with free or rpl_free. */ _GL_FUNCDECL_SYS (malloc, void *, (size_t size) + _GL_ATTRIBUTE_NOTHROW _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE); # endif # if defined GNULIB_POSIXCHECK && !_GL_USE_STDLIB_ALLOC @@ -1292,8 +1323,10 @@ _GL_CXXALIAS_RPL (realloc, void *, (void *ptr, size_t size)); # else # if __GNUC__ >= 11 /* For -Wmismatched-dealloc: Associate realloc with free or rpl_free. */ -_GL_FUNCDECL_SYS (realloc, void *, (void *ptr, size_t size) - _GL_ATTRIBUTE_DEALLOC_FREE); +_GL_FUNCDECL_SYS (realloc, void *, + (void *ptr, size_t size) + _GL_ATTRIBUTE_NOTHROW + _GL_ATTRIBUTE_DEALLOC_FREE); # endif _GL_CXXALIAS_SYS (realloc, void *, (void *ptr, size_t size)); # endif @@ -1303,8 +1336,10 @@ _GL_CXXALIASWARN (realloc); #else # if @GNULIB_FREE_POSIX@ && __GNUC__ >= 11 && !defined realloc /* For -Wmismatched-dealloc: Associate realloc with free or rpl_free. */ -_GL_FUNCDECL_SYS (realloc, void *, (void *ptr, size_t size) - _GL_ATTRIBUTE_DEALLOC_FREE); +_GL_FUNCDECL_SYS (realloc, void *, + (void *ptr, size_t size) + _GL_ATTRIBUTE_NOTHROW + _GL_ATTRIBUTE_DEALLOC_FREE); # endif # if defined GNULIB_POSIXCHECK && !_GL_USE_STDLIB_ALLOC # undef realloc diff --git a/lib/string.in.h b/lib/string.in.h index 912d0f7a30..f7e6f3b18e 100644 --- a/lib/string.in.h +++ b/lib/string.in.h @@ -45,7 +45,8 @@ #define _@GUARD_PREFIX@_STRING_H /* This file uses _GL_ATTRIBUTE_DEALLOC, _GL_ATTRIBUTE_MALLOC, - _GL_ATTRIBUTE_PURE, GNULIB_POSIXCHECK, HAVE_RAW_DECL_*. */ + _GL_ATTRIBUTE_NOTHROW, _GL_ATTRIBUTE_PURE, GNULIB_POSIXCHECK, + HAVE_RAW_DECL_*. */ #if !_GL_CONFIG_H_INCLUDED #error "Please include config.h first." #endif @@ -110,6 +111,28 @@ # endif #endif +/* _GL_ATTRIBUTE_NOTHROW declares that the function does not throw exceptions. + */ +#ifndef _GL_ATTRIBUTE_NOTHROW +# if defined __cplusplus +# if (__GNUC__ + (__GNUC_MINOR__ >= 8) > 2) || __clang_major >= 4 +# if __cplusplus >= 201103L +# define _GL_ATTRIBUTE_NOTHROW noexcept (true) +# else +# define _GL_ATTRIBUTE_NOTHROW throw () +# endif +# else +# define _GL_ATTRIBUTE_NOTHROW +# endif +# else +# if (__GNUC__ + (__GNUC_MINOR__ >= 3) > 3) || defined __clang__ +# define _GL_ATTRIBUTE_NOTHROW __attribute__ ((__nothrow__)) +# else +# define _GL_ATTRIBUTE_NOTHROW +# endif +# endif +#endif + /* The __attribute__ feature is available in gcc versions 2.5 and later. The attribute __pure__ was added in gcc 2.96. */ #ifndef _GL_ATTRIBUTE_PURE @@ -578,6 +601,7 @@ _GL_CXXALIAS_MDA (strdup, char *, (char const *__s)); # if (!@HAVE_DECL_STRDUP@ || __GNUC__ >= 11) && !defined strdup _GL_FUNCDECL_SYS (strdup, char *, (char const *__s) + _GL_ATTRIBUTE_NOTHROW _GL_ARG_NONNULL ((1)) _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE); # endif @@ -589,6 +613,7 @@ _GL_CXXALIASWARN (strdup); /* For -Wmismatched-dealloc: Associate strdup with free or rpl_free. */ _GL_FUNCDECL_SYS (strdup, char *, (char const *__s) + _GL_ATTRIBUTE_NOTHROW _GL_ARG_NONNULL ((1)) _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE); # endif @@ -661,6 +686,7 @@ _GL_CXXALIAS_RPL (strndup, char *, (char const *__s, size_t __n)); # if !@HAVE_DECL_STRNDUP@ || (__GNUC__ >= 11 && !defined strndup) _GL_FUNCDECL_SYS (strndup, char *, (char const *__s, size_t __n) + _GL_ATTRIBUTE_NOTHROW _GL_ARG_NONNULL ((1)) _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE); # endif @@ -672,6 +698,7 @@ _GL_CXXALIASWARN (strndup); /* For -Wmismatched-dealloc: Associate strndup with free or rpl_free. */ _GL_FUNCDECL_SYS (strndup, char *, (char const *__s, size_t __n) + _GL_ATTRIBUTE_NOTHROW _GL_ARG_NONNULL ((1)) _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE); # endif diff --git a/lib/sys_stat.in.h b/lib/sys_stat.in.h index ad4da17fa4..3da98eb382 100644 --- a/lib/sys_stat.in.h +++ b/lib/sys_stat.in.h @@ -55,17 +55,41 @@ #ifndef _@GUARD_PREFIX@_SYS_STAT_H #define _@GUARD_PREFIX@_SYS_STAT_H -/* This file uses GNULIB_POSIXCHECK, HAVE_RAW_DECL_*. */ +/* This file uses _GL_ATTRIBUTE_NOTHROW, GNULIB_POSIXCHECK, HAVE_RAW_DECL_*. */ #if !_GL_CONFIG_H_INCLUDED #error "Please include config.h first." #endif + +/* _GL_ATTRIBUTE_NOTHROW declares that the function does not throw exceptions. + */ +#ifndef _GL_ATTRIBUTE_NOTHROW +# if defined __cplusplus +# if (__GNUC__ + (__GNUC_MINOR__ >= 8) > 2) || __clang_major >= 4 +# if __cplusplus >= 201103L +# define _GL_ATTRIBUTE_NOTHROW noexcept (true) +# else +# define _GL_ATTRIBUTE_NOTHROW throw () +# endif +# else +# define _GL_ATTRIBUTE_NOTHROW +# endif +# else +# if (__GNUC__ + (__GNUC_MINOR__ >= 3) > 3) || defined __clang__ +# define _GL_ATTRIBUTE_NOTHROW __attribute__ ((__nothrow__)) +# else +# define _GL_ATTRIBUTE_NOTHROW +# endif +# endif +#endif + /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ /* The definition of _GL_ARG_NONNULL is copied here. */ /* The definition of _GL_WARN_ON_USE is copied here. */ + /* Before doing "#define mknod rpl_mknod" below, we need to include all headers that may declare mknod(). OS/2 kLIBC declares mknod() in <unistd.h>, not in <sys/stat.h>. */ @@ -575,7 +599,7 @@ _GL_WARN_ON_USE (futimens, "futimens is not portable - " #if @GNULIB_GETUMASK@ # if !@HAVE_GETUMASK@ -_GL_FUNCDECL_SYS (getumask, mode_t, (void)); +_GL_FUNCDECL_SYS (getumask, mode_t, (void) _GL_ATTRIBUTE_NOTHROW); # endif _GL_CXXALIAS_SYS (getumask, mode_t, (void)); # if @HAVE_GETUMASK@ diff --git a/lib/wchar.in.h b/lib/wchar.in.h index 510f202537..f40c800bc9 100644 --- a/lib/wchar.in.h +++ b/lib/wchar.in.h @@ -85,7 +85,8 @@ #define _@GUARD_PREFIX@_WCHAR_H /* This file uses _GL_ATTRIBUTE_DEALLOC, _GL_ATTRIBUTE_MALLOC, - _GL_ATTRIBUTE_PURE, GNULIB_POSIXCHECK, HAVE_RAW_DECL_*. */ + _GL_ATTRIBUTE_NOTHROW, _GL_ATTRIBUTE_PURE, GNULIB_POSIXCHECK, + HAVE_RAW_DECL_*. */ #if !_GL_CONFIG_H_INCLUDED #error "Please include config.h first." #endif @@ -136,6 +137,28 @@ # endif #endif +/* _GL_ATTRIBUTE_NOTHROW declares that the function does not throw exceptions. + */ +#ifndef _GL_ATTRIBUTE_NOTHROW +# if defined __cplusplus +# if (__GNUC__ + (__GNUC_MINOR__ >= 8) > 2) || __clang_major >= 4 +# if __cplusplus >= 201103L +# define _GL_ATTRIBUTE_NOTHROW noexcept (true) +# else +# define _GL_ATTRIBUTE_NOTHROW throw () +# endif +# else +# define _GL_ATTRIBUTE_NOTHROW +# endif +# else +# if (__GNUC__ + (__GNUC_MINOR__ >= 3) > 3) || defined __clang__ +# define _GL_ATTRIBUTE_NOTHROW __attribute__ ((__nothrow__)) +# else +# define _GL_ATTRIBUTE_NOTHROW +# endif +# endif +#endif + /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ /* The definition of _GL_ARG_NONNULL is copied here. */ @@ -1305,6 +1328,7 @@ _GL_CXXALIAS_MDA (wcsdup, wchar_t *, (const wchar_t *s)); # if !@HAVE_WCSDUP@ || (defined __sun && defined __cplusplus) || __GNUC__ >= 11 _GL_FUNCDECL_SYS (wcsdup, wchar_t *, (const wchar_t *s) + _GL_ATTRIBUTE_NOTHROW _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE); # endif _GL_CXXALIAS_SYS (wcsdup, wchar_t *, (const wchar_t *s)); @@ -1315,6 +1339,7 @@ _GL_CXXALIASWARN (wcsdup); /* For -Wmismatched-dealloc: Associate wcsdup with free or rpl_free. */ _GL_FUNCDECL_SYS (wcsdup, wchar_t *, (const wchar_t *s) + _GL_ATTRIBUTE_NOTHROW _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE); # endif # if defined GNULIB_POSIXCHECK @@ -1336,6 +1361,7 @@ _GL_CXXALIAS_MDA (wcsdup, wchar_t *, (const wchar_t *s)); # else _GL_FUNCDECL_SYS (wcsdup, wchar_t *, (const wchar_t *s) + _GL_ATTRIBUTE_NOTHROW _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE); # if @HAVE_DECL_WCSDUP@ _GL_CXXALIAS_SYS (wcsdup, wchar_t *, (const wchar_t *s));