summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Meyering <meyering@fb.com>2017-05-21 09:23:18 -0700
committerJim Meyering <meyering@fb.com>2017-05-21 12:07:57 -0700
commit1e1e23358050f201f5630a16609c441b9e7955a0 (patch)
tree647047b09474367701bfc1a8b45c4907145aceee
parent9e2c89397916d9587f1945528eb5d5651c0b4edb (diff)
downloadgrep-1e1e23358050f201f5630a16609c441b9e7955a0.tar.gz
maint: accommodate GCC7's -Werror=duplicated-branches
* src/system.h (IGNORE_DUPLICATE_BRANCH_WARNING): Define. * src/grep.c (grepfile): Use it. * src/kwset.c (bmexec, acexec): Use it.
-rw-r--r--src/grep.c3
-rw-r--r--src/kwset.c15
-rw-r--r--src/system.h14
3 files changed, 24 insertions, 8 deletions
diff --git a/src/grep.c b/src/grep.c
index 1958e264..bc2599f3 100644
--- a/src/grep.c
+++ b/src/grep.c
@@ -1700,7 +1700,8 @@ static bool
grepfile (int dirdesc, char const *name, bool follow, bool command_line)
{
int oflag = (O_RDONLY | O_NOCTTY
- | (binary ? O_BINARY : 0)
+ | (IGNORE_DUPLICATE_BRANCH_WARNING
+ (binary ? O_BINARY : 0))
| (follow ? 0 : O_NOFOLLOW)
| (skip_devices (command_line) ? O_NONBLOCK : 0));
int desc = openat_safer (dirdesc, name, oflag);
diff --git a/src/kwset.c b/src/kwset.c
index 2599af5a..a2ce6b6b 100644
--- a/src/kwset.c
+++ b/src/kwset.c
@@ -756,10 +756,10 @@ bmexec (kwset_t kwset, char const *text, ptrdiff_t size,
{
/* Help the compiler inline in two ways, depending on whether
kwset->trans is null. */
- ptrdiff_t ret = (kwset->trans
- ? bmexec_trans (kwset, text, size)
- : bmexec_trans (kwset, text, size));
-
+ ptrdiff_t ret = (IGNORE_DUPLICATE_BRANCH_WARNING
+ (kwset->trans
+ ? bmexec_trans (kwset, text, size)
+ : bmexec_trans (kwset, text, size)));
if (0 <= ret)
{
kwsmatch->index = 0;
@@ -905,9 +905,10 @@ acexec (kwset_t kwset, char const *text, ptrdiff_t size,
assume (0 <= size);
/* Help the compiler inline in two ways, depending on whether
kwset->trans is null. */
- return (kwset->trans
- ? acexec_trans (kwset, text, size, kwsmatch, longest)
- : acexec_trans (kwset, text, size, kwsmatch, longest));
+ return (IGNORE_DUPLICATE_BRANCH_WARNING
+ (kwset->trans
+ ? acexec_trans (kwset, text, size, kwsmatch, longest)
+ : acexec_trans (kwset, text, size, kwsmatch, longest)));
}
/* Find the first instance of a KWSET member in TEXT, which has SIZE bytes.
diff --git a/src/system.h b/src/system.h
index f9747935..bac78235 100644
--- a/src/system.h
+++ b/src/system.h
@@ -115,4 +115,18 @@ __asan_unpoison_memory_region (void const volatile *addr, size_t size) { }
# endif
#endif
+/* When we deliberately use duplicate branches, use this macro to
+ disable gcc's -Wduplicated-branches in the containing expression. */
+#if 7 <= __GNUC__
+# define IGNORE_DUPLICATE_BRANCH_WARNING(exp) \
+ ({ \
+ _Pragma ("GCC diagnostic push") \
+ _Pragma ("GCC diagnostic ignored \"-Wduplicated-branches\"") \
+ exp; \
+ _Pragma ("GCC diagnostic pop") \
+ })
+#else
+# define IGNORE_DUPLICATE_BRANCH_WARNING(exp) exp
+#endif
+
#endif