[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
copy-file: Silence gcc warnings
From: |
Bruno Haible |
Subject: |
copy-file: Silence gcc warnings |
Date: |
Fri, 26 May 2023 19:34:24 +0200 |
In GNU gettext, I see these compilation warnings with gcc 13.1.0:
gcc ... -Wall -Wno-cast-qual -Wno-conversion -Wno-float-equal -Wno-sign-compare
-Wno-undef -Wno-unused-function -Wno-unused-parameter -Wno-float-conversion
-Wimplicit-fallthrough -Wno-pedantic -Wno-sign-conversion -Wno-type-limits
-Wno-unsuffixed-float-constants -g -O2 -c copy-file.c -fPIC -DPIC -o
.libs/libgettextlib_la-copy-file.o
copy-file.c: In function 'copy_file_preserving':
copy-file.c:192:7: warning: this statement may fall through
[-Wimplicit-fallthrough=]
192 | error (EXIT_FAILURE, errno, _("error while opening %s for
reading"),
|
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
193 | quote (src_filename));
| ~~~~~~~~~~~~~~~~~~~~~
copy-file.c:195:5: note: here
195 | case GL_COPY_ERR_OPEN_BACKUP_WRITE:
| ^~~~
and so on.
The option -Wimplicit-fallthrough gets added as part of GL_CFLAG_GNULIB_WARNINGS
(collected by gl_CC_GNULIB_WARNINGS in m4/gnulib-common.m4). That explains
why I'm not seeing these warnings in gnulib testdirs.
It's probably too hard to teach gcc that error (EXIT_FAILURE, ...) does not
return but error (0, ...) does return. Therefore just disabling this warning
seems the best action.
2023-05-26 Bruno Haible <bruno@clisp.org>
copy-file: Silence gcc warnings.
* lib/copy-file.c: Add #pragma GCC diagnostic.
diff --git a/lib/copy-file.c b/lib/copy-file.c
index 78da3996bb..bd98b35e7e 100644
--- a/lib/copy-file.c
+++ b/lib/copy-file.c
@@ -180,6 +180,13 @@ 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)
{
- copy-file: Silence gcc warnings,
Bruno Haible <=
- Re: copy-file: Silence gcc warnings, Pádraig Brady, 2023/05/26
- Re: copy-file: Silence gcc warnings, Bruno Haible, 2023/05/26
- Re: copy-file: Silence gcc warnings, Paul Eggert, 2023/05/26
- error: Support the compiler's control flow analysis better (was: copy-file: Silence gcc warnings), Bruno Haible, 2023/05/27
- Re: error: Support the compiler's control flow analysis better (was: copy-file: Silence gcc warnings), Pádraig Brady, 2023/05/28
- Re: error: Support the compiler's control flow analysis better (was: copy-file: Silence gcc warnings), Pádraig Brady, 2023/05/28
- Re: error: Support the compiler's control flow analysis better (was: copy-file: Silence gcc warnings), Pádraig Brady, 2023/05/28
- Re: error: Support the compiler's control flow analysis better, Bruno Haible, 2023/05/28
- Re: error: Support the compiler's control flow analysis better (was: copy-file: Silence gcc warnings), Paul Eggert, 2023/05/30
- Re: error: Support the compiler's control flow analysis better (was: copy-file: Silence gcc warnings), Pádraig Brady, 2023/05/31