]> Savannah Git Hosting - gnulib.git/commitdiff
dirent: Improve GCC 11 allocation-deallocation checking.
authorBruno Haible <bruno@clisp.org>
Sun, 8 Aug 2021 16:23:46 +0000 (18:23 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 8 Aug 2021 16:23:46 +0000 (18:23 +0200)
* 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
lib/dirent.in.h

index ffaa129355d4659948282c44e4ca2a896608d7d6..9e06762f84c17fdbc53495389174c94ccd73d243 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2021-08-08  Bruno Haible  <bruno@clisp.org>
+
+       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  <bruno@clisp.org>
 
        stdlib, string, wchar: Improve GCC 11 allocation-deallocation checking.
index 49e0aa90eaf7cdb02cf263617298ec339d3c9e44..5775edf09437c8a199c854daf9a0873b8896db55 100644 (file)
@@ -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