]> Savannah Git Hosting - gnulib.git/commitdiff
error: Support the compiler's control flow analysis better.
authorBruno Haible <bruno@clisp.org>
Sat, 27 May 2023 20:39:59 +0000 (22:39 +0200)
committerBruno Haible <bruno@clisp.org>
Sat, 27 May 2023 20:39:59 +0000 (22:39 +0200)
* lib/error.in.h: Remove @PRAGMA_SYSTEM_HEADER@. Include <stdlib.h>.
(error): Define as a macro that explicitly invokes exit().
(error_at_line): Likewise.
* lib/error.c (_GL_NO_INLINE_ERROR): Define before including error.h.
* modules/error-h (configure.ac): Don't invoke gl_CONDITIONAL_HEADER.
(Makefile.am): Generate error.h always. Don't substitute
PRAGMA_SYSTEM_HEADER.
* m4/error_h.m4 (gl_ERROR_H): Set COMPILE_ERROR_C instead of
GL_GENERATE_ERROR_H.
* modules/error (configure.ac, Depends-on): Test COMPILE_ERROR_C instead
of GL_GENERATE_ERROR_H.
* lib/copy-file.c: Revert the last change.

ChangeLog
lib/copy-file.c
lib/error.c
lib/error.in.h
m4/error_h.m4
modules/error
modules/error-h

index fc12332373bbce3ba8653db7199b56a8c8dc47c2..0912f8e6349819256288e6c21c2ac6fa22e3d252 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2023-05-27  Bruno Haible  <bruno@clisp.org>
+
+       error: Support the compiler's control flow analysis better.
+       * lib/error.in.h: Remove @PRAGMA_SYSTEM_HEADER@. Include <stdlib.h>.
+       (error): Define as a macro that explicitly invokes exit().
+       (error_at_line): Likewise.
+       * lib/error.c (_GL_NO_INLINE_ERROR): Define before including error.h.
+       * modules/error-h (configure.ac): Don't invoke gl_CONDITIONAL_HEADER.
+       (Makefile.am): Generate error.h always. Don't substitute
+       PRAGMA_SYSTEM_HEADER.
+       * m4/error_h.m4 (gl_ERROR_H): Set COMPILE_ERROR_C instead of
+       GL_GENERATE_ERROR_H.
+       * modules/error (configure.ac, Depends-on): Test COMPILE_ERROR_C instead
+       of GL_GENERATE_ERROR_H.
+       * lib/copy-file.c: Revert the last change.
+
 2023-05-26  Bruno Haible  <bruno@clisp.org>
 
        flexmember: Make it easier to use.
index bd98b35e7eb299667890a94599d2052d447f5ad8..78da3996bb94af70397a69e3fd93120c530ada91 100644 (file)
@@ -180,13 +180,6 @@ qcopy_file_preserving (const char *src_filename, const char *dest_filename)
   return err;
 }
 
-/* Silence gcc warnings "this statement may fall through".
-   gcc cannot know that error(), when invoked with a non-zero status argument,
-   will not return.  */
-#if __GNUC__ >= 7
-#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
-#endif
-
 void
 copy_file_preserving (const char *src_filename, const char *dest_filename)
 {
index ef4372875f8dfee4b0a68aeeef9f4cc3edfb955b..9e26391e98ad190ed18b7be54338f37b4a691c82 100644 (file)
@@ -19,6 +19,7 @@
 
 #if !_LIBC
 # include <config.h>
+# define _GL_NO_INLINE_ERROR
 #endif
 
 #include "error.h"
index 9a520f1ee3e3f9352c14343fa8325872ec8220dc..4bf191e102f6dba2afaf2fadf45f04e05b7b1b4d 100644 (file)
@@ -18,9 +18,9 @@
 
 #ifndef _@GUARD_PREFIX@_ERROR_H
 
-#if __GNUC__ >= 3
-@PRAGMA_SYSTEM_HEADER@
-#endif
+/* No @PRAGMA_SYSTEM_HEADER@ here, because it would prevent
+   -Wimplicit-fallthrough warnings for missing FALLTHROUGH after error(...)
+   or error_at_line(...) invocations.  */
 
 /* The include_next requires a split double-inclusion guard.  */
 #if @HAVE_ERROR_H@
@@ -38,6 +38,9 @@
 /* Get _GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, _GL_ATTRIBUTE_SPEC_PRINTF_SYSTEM.  */
 #include <stdio.h>
 
+/* Get exit().  */
+#include <stdlib.h>
+
 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here.  */
 
 #if GNULIB_VFPRINTF_POSIX
@@ -63,6 +66,11 @@ _GL_FUNCDECL_RPL (error, void,
                   _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_ERROR, 3, 4)));
 _GL_CXXALIAS_RPL (error, void,
                   (int __status, int __errnum, const char *__format, ...));
+# ifndef _GL_NO_INLINE_ERROR
+#  undef error
+#  define error(status, ...) \
+     ((rpl_error)(0, __VA_ARGS__), (status) ? exit (status) : (void)0)
+# endif
 #else
 # if ! @HAVE_ERROR@
 _GL_FUNCDECL_SYS (error, void,
@@ -71,6 +79,10 @@ _GL_FUNCDECL_SYS (error, void,
 # endif
 _GL_CXXALIAS_SYS (error, void,
                   (int __status, int __errnum, const char *__format, ...));
+# ifndef _GL_NO_INLINE_ERROR
+#  define error(status, ...) \
+     ((error)(0, __VA_ARGS__), (status) ? exit (status) : (void)0)
+# endif
 #endif
 #if __GLIBC__ >= 2
 _GL_CXXALIASWARN (error);
@@ -90,6 +102,11 @@ _GL_FUNCDECL_RPL (error_at_line, void,
 _GL_CXXALIAS_RPL (error_at_line, void,
                   (int __status, int __errnum, const char *__filename,
                    unsigned int __lineno, const char *__format, ...));
+# ifndef _GL_NO_INLINE_ERROR
+#  undef error_at_line
+#  define error_at_line(status, ...) \
+     ((rpl_error_at_line)(0, __VA_ARGS__), (status) ? exit (status) : (void)0)
+# endif
 #else
 # if ! @HAVE_ERROR_AT_LINE@
 _GL_FUNCDECL_SYS (error_at_line, void,
@@ -100,6 +117,10 @@ _GL_FUNCDECL_SYS (error_at_line, void,
 _GL_CXXALIAS_SYS (error_at_line, void,
                   (int __status, int __errnum, const char *__filename,
                    unsigned int __lineno, const char *__format, ...));
+# ifndef _GL_NO_INLINE_ERROR
+#  define error_at_line(status, ...) \
+     ((error_at_line)(0, __VA_ARGS__), (status) ? exit (status) : (void)0)
+# endif
 #endif
 _GL_CXXALIASWARN (error_at_line);
 
index f38e4ead1322af2c9f448ce57de6b25eb8edfcd0..e8a58f6fbd54bb6de295a97c501c7efee5ae3a48 100644 (file)
@@ -1,4 +1,4 @@
-# error_h.m4 serial 3
+# error_h.m4 serial 4
 dnl Copyright (C) 1996-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,
@@ -112,10 +112,9 @@ AC_DEFUN_ONCE([gl_ERROR_H],
 
   if test $HAVE_ERROR = 0 || test $REPLACE_ERROR = 1 \
      || test $HAVE_ERROR_AT_LINE = 0 || test $REPLACE_ERROR_AT_LINE = 1; then
-    dnl Provide a substitute <error.h> file.
-    GL_GENERATE_ERROR_H=true
+    COMPILE_ERROR_C=1
   else
-    GL_GENERATE_ERROR_H=false
+    COMPILE_ERROR_C=0
   fi
 
   AC_SUBST([HAVE_ERROR])
index 5f716865a93ceeb07297aa3bb93414c0fd5ff24e..63317f1821b68ba4cd9b0dae6c7dc263179dbb91 100644 (file)
@@ -9,14 +9,14 @@ Depends-on:
 error-h
 stdio
 getprogname
-strerror        [test $GL_GENERATE_ERROR_H = true]
-unistd          [test $GL_GENERATE_ERROR_H = true]
-msvc-nothrow    [test $GL_GENERATE_ERROR_H = true]
+strerror        [test $COMPILE_ERROR_C = 1]
+unistd          [test $COMPILE_ERROR_C = 1]
+msvc-nothrow    [test $COMPILE_ERROR_C = 1]
 
 configure.ac:
 AC_REQUIRE([gl_ERROR_H])
 gl_ERROR
-gl_CONDITIONAL([GL_COND_OBJ_ERROR], [test $GL_GENERATE_ERROR_H = true])
+gl_CONDITIONAL([GL_COND_OBJ_ERROR], [test $COMPILE_ERROR_C = 1])
 AM_COND_IF([GL_COND_OBJ_ERROR], [
   gl_PREREQ_ERROR
 ])
index a84d8e2705462cc9bdcfc46f668ecf57b99e4597..b6618d3c765129de2e55fd672588f72c858f7535 100644 (file)
@@ -11,22 +11,18 @@ snippet/c++defs
 
 configure.ac:
 gl_ERROR_H
-gl_CONDITIONAL_HEADER([error.h])
 AC_PROG_MKDIR_P
 
 Makefile.am:
-BUILT_SOURCES += $(ERROR_H)
+BUILT_SOURCES += error.h
 
-# We need the following in order to create <error.h> when the system
-# doesn't have one that works.
-if GL_GENERATE_ERROR_H
+# We need the following in order to override <error.h>.
 error.h: error.in.h $(top_builddir)/config.status $(CXXDEFS_H)
 @NMD@  $(AM_V_GEN)$(MKDIR_P) '%reldir%'
        $(gl_V_at)$(SED_HEADER_STDOUT) \
              -e 's|@''GUARD_PREFIX''@|${gl_include_guard_prefix}|g' \
              -e 's|@''HAVE_ERROR_H''@|$(HAVE_ERROR_H)|g' \
              -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
-             -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
              -e 's|@''NEXT_ERROR_H''@|$(NEXT_ERROR_H)|g' \
              -e 's|@''HAVE_ERROR''@|$(HAVE_ERROR)|g' \
              -e 's|@''HAVE_ERROR_AT_LINE''@|$(HAVE_ERROR_AT_LINE)|g' \
@@ -35,10 +31,6 @@ error.h: error.in.h $(top_builddir)/config.status $(CXXDEFS_H)
              -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
              $(srcdir)/error.in.h > $@-t
        $(AM_V_at)mv $@-t $@
-else
-error.h: $(top_builddir)/config.status
-       rm -f $@
-endif
 MOSTLYCLEANFILES += error.h error.h-t
 
 Include: