[pacman-dev] [PATCH] Use attribute to declare case statement fallthroughs

Allan McRae allan at archlinux.org
Mon May 17 10:03:34 UTC 2021


Clang does not recognise the comment style notification of expected
case statement fallthrough.

Signed-off-by: Allan McRae <allan at archlinux.org>
---
 lib/libalpm/sync.c  | 2 +-
 src/pacman/pacman.c | 5 +++--
 src/pacman/util.c   | 1 +
 3 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
index 7ef558c4..36ad6242 100644
--- a/lib/libalpm/sync.c
+++ b/lib/libalpm/sync.c
@@ -1026,7 +1026,7 @@ static int check_validity(alpm_handle_t *handle,
 							v->siglevel & ALPM_SIG_PACKAGE_OPTIONAL,
 							v->siglevel & ALPM_SIG_PACKAGE_MARGINAL_OK,
 							v->siglevel & ALPM_SIG_PACKAGE_UNKNOWN_OK);
-					/* fallthrough */
+					__attribute__((fallthrough));
 				case ALPM_ERR_PKG_INVALID_CHECKSUM:
 					prompt_to_delete(handle, v->path, v->error);
 					break;
diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
index 7e810127..e398855a 100644
--- a/src/pacman/pacman.c
+++ b/src/pacman/pacman.c
@@ -196,7 +196,7 @@ static void usage(int op, const char * const myname)
 				addlist(_("      --ignore <pkg>   ignore a package upgrade (can be used more than once)\n"));
 				addlist(_("      --ignoregroup <grp>\n"
 				          "                       ignore a group upgrade (can be used more than once)\n"));
-				/* fall through */
+				__attribute__((fallthrough));
 			case PM_OP_REMOVE:
 				addlist(_("  -d, --nodeps         skip dependency version checks (-dd to skip all checks)\n"));
 				addlist(_("      --assume-installed <package=version>\n"
@@ -412,7 +412,8 @@ static int parsearg_global(int opt)
 				unsigned short debug = (unsigned short)atoi(optarg);
 				switch(debug) {
 					case 2:
-						config->logmask |= ALPM_LOG_FUNCTION; /* fall through */
+						config->logmask |= ALPM_LOG_FUNCTION;
+						__attribute__((fallthrough));
 					case 1:
 						config->logmask |= ALPM_LOG_DEBUG;
 						break;
diff --git a/src/pacman/util.c b/src/pacman/util.c
index 59d6a72e..5486e7a5 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -1069,6 +1069,7 @@ static char *pkg_get_location(alpm_pkg_t *pkg)
 			}
 
 			/* fallthrough - for theoretical serverless repos */
+			__attribute__((fallthrough));
 
 		case ALPM_PKG_FROM_FILE:
 			return strdup(alpm_pkg_get_filename(pkg));
-- 
2.31.1


More information about the pacman-dev mailing list