From 0b53edc950141d4d060b44756beb972b222b9160 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 8 Aug 2021 18:23:46 +0200 Subject: [PATCH] dirent: Improve GCC 11 allocation-deallocation checking. * lib/dirent.in.h (opendir): For GCC >= 11: Declare also when the platform already declares the function or when the module 'opendir' is not in use. (fdopendir): For GCC >= 11: Declare also when the platform already declares the function or when the module 'fdopendir' is not in use. --- ChangeLog | 9 +++++++++ lib/dirent.in.h | 35 +++++++++++++++++++++++++++-------- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index ffaa129355..9e06762f84 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2021-08-08 Bruno Haible + + dirent: Improve GCC 11 allocation-deallocation checking. + * lib/dirent.in.h (opendir): For GCC >= 11: Declare also when the + platform already declares the function or when the module 'opendir' is + not in use. + (fdopendir): For GCC >= 11: Declare also when the platform already + declares the function or when the module 'fdopendir' is not in use. + 2021-08-08 Bruno Haible stdlib, string, wchar: Improve GCC 11 allocation-deallocation checking. diff --git a/lib/dirent.in.h b/lib/dirent.in.h index 49e0aa90ea..5775edf094 100644 --- a/lib/dirent.in.h +++ b/lib/dirent.in.h @@ -111,7 +111,7 @@ _GL_FUNCDECL_RPL (opendir, DIR *, _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC (closedir, 1)); _GL_CXXALIAS_RPL (opendir, DIR *, (const char *dir_name)); # else -# if !@HAVE_OPENDIR@ +# if !@HAVE_OPENDIR@ || __GNUC__ >= 11 _GL_FUNCDECL_SYS (opendir, DIR *, (const char *dir_name) _GL_ARG_NONNULL ((1)) @@ -120,11 +120,21 @@ _GL_FUNCDECL_SYS (opendir, DIR *, _GL_CXXALIAS_SYS (opendir, DIR *, (const char *dir_name)); # endif _GL_CXXALIASWARN (opendir); -#elif defined GNULIB_POSIXCHECK -# undef opendir -# if HAVE_RAW_DECL_OPENDIR +#else +# if @GNULIB_CLOSEDIR@ && __GNUC__ >= 11 && !defined opendir +/* For -Wmismatched-dealloc: Associate opendir with closedir or + rpl_closedir. */ +_GL_FUNCDECL_SYS (opendir, DIR *, + (const char *dir_name) + _GL_ARG_NONNULL ((1)) + _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC (closedir, 1)); +# endif +# if defined GNULIB_POSIXCHECK +# undef opendir +# if HAVE_RAW_DECL_OPENDIR _GL_WARN_ON_USE (opendir, "opendir is not portable - " "use gnulib module opendir for portability"); +# endif # endif #endif @@ -211,7 +221,7 @@ _GL_FUNCDECL_RPL (fdopendir, DIR *, _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC (closedir, 1)); _GL_CXXALIAS_RPL (fdopendir, DIR *, (int fd)); # else -# if !@HAVE_FDOPENDIR@ || !@HAVE_DECL_FDOPENDIR@ +# if !@HAVE_FDOPENDIR@ || !@HAVE_DECL_FDOPENDIR@ || __GNUC__ >= 11 _GL_FUNCDECL_SYS (fdopendir, DIR *, (int fd) _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC (closedir, 1)); @@ -219,11 +229,20 @@ _GL_FUNCDECL_SYS (fdopendir, DIR *, _GL_CXXALIAS_SYS (fdopendir, DIR *, (int fd)); # endif _GL_CXXALIASWARN (fdopendir); -#elif defined GNULIB_POSIXCHECK -# undef fdopendir -# if HAVE_RAW_DECL_FDOPENDIR +#else +# if @GNULIB_CLOSEDIR@ && __GNUC__ >= 11 && !defined fdopendir +/* For -Wmismatched-dealloc: Associate fdopendir with closedir or + rpl_closedir. */ +_GL_FUNCDECL_SYS (fdopendir, DIR *, + (int fd) + _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC (closedir, 1)); +# endif +# if defined GNULIB_POSIXCHECK +# undef fdopendir +# if HAVE_RAW_DECL_FDOPENDIR _GL_WARN_ON_USE (fdopendir, "fdopendir is unportable - " "use gnulib module fdopendir for portability"); +# endif # endif #endif -- 2.39.5