summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2021-06-02 14:09:18 -0400
committerTavian Barnes <tavianator@tavianator.com>2021-06-02 14:09:18 -0400
commitea6155677e0f466d05a0027fdbe29827f4a08c2c (patch)
treed2b8ab2d6f8921d6e5ad29b4fb58368533a0c02b
parent69a5227098b87b048a90ceb1ca7b169c02ba151e (diff)
downloadbfs-ea6155677e0f466d05a0027fdbe29827f4a08c2c.tar.xz
Enable -Wimplicit-fallthrough
-rw-r--r--Makefile9
-rw-r--r--parse.c10
-rw-r--r--printf.c2
-rw-r--r--util.h14
4 files changed, 28 insertions, 7 deletions
diff --git a/Makefile b/Makefile
index 994962f..5d70c6e 100644
--- a/Makefile
+++ b/Makefile
@@ -33,7 +33,14 @@ INSTALL ?= install
MKDIR ?= mkdir -p
RM ?= rm -f
-DEFAULT_CFLAGS ?= -g -Wall -Wmissing-declarations -Wshadow -Wsign-compare -Wstrict-prototypes
+DEFAULT_CFLAGS := \
+ -g \
+ -Wall \
+ -Wmissing-declarations \
+ -Wshadow \
+ -Wsign-compare \
+ -Wstrict-prototypes \
+ -Wimplicit-fallthrough
CFLAGS ?= $(DEFAULT_CFLAGS)
LDFLAGS ?=
diff --git a/parse.c b/parse.c
index 2475290..6ad580b 100644
--- a/parse.c
+++ b/parse.c
@@ -1800,7 +1800,7 @@ static int parse_mode(const struct parser_state *state, const char *mode, struct
case MODE_CLAUSE:
who = 0;
mstate = MODE_WHO;
- // Fallthrough
+ fallthrough;
case MODE_WHO:
switch (*i) {
@@ -1827,7 +1827,7 @@ static int parse_mode(const struct parser_state *state, const char *mode, struct
case MODE_EQUALS:
expr->file_mode &= ~who;
expr->dir_mode &= ~who;
- // Fallthrough
+ fallthrough;
case MODE_PLUS:
expr->file_mode |= file_change;
expr->dir_mode |= dir_change;
@@ -1837,7 +1837,7 @@ static int parse_mode(const struct parser_state *state, const char *mode, struct
expr->dir_mode &= ~dir_change;
break;
}
- // Fallthrough
+ fallthrough;
case MODE_ACTION:
if (who == 0) {
@@ -1919,7 +1919,7 @@ static int parse_mode(const struct parser_state *state, const char *mode, struct
break;
case 'x':
file_change |= who & 0111;
- // Fallthrough
+ fallthrough;
case 'X':
dir_change |= who & 0111;
break;
@@ -1982,7 +1982,7 @@ static struct expr *parse_perm(struct parser_state *state, int field, int arg2)
++mode;
break;
}
- // Fallthrough
+ fallthrough;
default:
expr->mode_cmp = MODE_EXACT;
break;
diff --git a/printf.c b/printf.c
index 4a2c65a..26c19a7 100644
--- a/printf.c
+++ b/printf.c
@@ -630,7 +630,7 @@ struct bfs_printf *bfs_printf_parse(const struct bfs_ctx *ctx, const char *forma
case '0':
case '+':
must_be_numeric = true;
- // Fallthrough
+ fallthrough;
case ' ':
case '-':
if (strchr(directive->str, c)) {
diff --git a/util.h b/util.h
index 1b52513..7b8b877 100644
--- a/util.h
+++ b/util.h
@@ -42,6 +42,12 @@
# define BFS_HAS_INCLUDE(header, fallback) fallback
#endif
+#ifdef __has_c_attribute
+# define BFS_HAS_C_ATTRIBUTE(attr) __has_c_attribute(attr)
+#else
+# define BFS_HAS_C_ATTRIBUTE(attr) false
+#endif
+
#ifndef BFS_HAS_MNTENT
# define BFS_HAS_MNTENT BFS_HAS_INCLUDE(<mntent.h>, __GLIBC__)
#endif
@@ -86,6 +92,14 @@
# define O_DIRECTORY 0
#endif
+#if BFS_HAS_C_ATTRIBUTE(fallthrough)
+# define fallthrough [[fallthrough]]
+#elif __GNUC__
+# define fallthrough __attribute__((fallthrough))
+#else
+# define fallthrough
+#endif
+
/**
* Adds compiler warnings for bad printf()-style function calls, if supported.
*/