From a1afe9afc6879960389491b6fb587f14ae1ae5df Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@musicpd.org>
Date: Mon, 23 Dec 2019 17:47:01 +0100
Subject: [PATCH] util/Compiler.h: add gcc_fallthrough

Works around build failures with ccache which may feed processed code
to GCC, which doesn't have the "fall through" code comments.
---
 src/player/Thread.cxx | 2 ++
 src/util/Compiler.h   | 6 ++++++
 src/util/format.c     | 2 ++
 3 files changed, 10 insertions(+)

diff --git a/src/player/Thread.cxx b/src/player/Thread.cxx
index 05e691bd1..64a502e6d 100644
--- a/src/player/Thread.cxx
+++ b/src/player/Thread.cxx
@@ -46,6 +46,7 @@
 #include "CrossFade.hxx"
 #include "tag/Tag.hxx"
 #include "Idle.hxx"
+#include "util/Compiler.h"
 #include "util/Domain.hxx"
 #include "thread/Name.hxx"
 #include "Log.hxx"
@@ -1171,6 +1172,7 @@ try {
 			}
 
 			/* fall through */
+			gcc_fallthrough;
 
 		case PlayerCommand::PAUSE:
 			next_song.reset();
diff --git a/src/util/Compiler.h b/src/util/Compiler.h
index 6a64ad098..a97b34529 100644
--- a/src/util/Compiler.h
+++ b/src/util/Compiler.h
@@ -143,6 +143,12 @@
 #define gcc_flatten
 #endif
 
+#if CLANG_OR_GCC_VERSION(7,0)
+#define gcc_fallthrough __attribute__((fallthrough))
+#else
+#define gcc_fallthrough
+#endif
+
 #ifndef __cplusplus
 /* plain C99 has "restrict" */
 #define gcc_restrict restrict
diff --git a/src/util/format.c b/src/util/format.c
index 62099b32e..10b53c771 100644
--- a/src/util/format.c
+++ b/src/util/format.c
@@ -19,6 +19,7 @@
  */
 
 #include "format.h"
+#include "util/Compiler.h"
 
 #include <stdbool.h>
 #include <stdio.h>
@@ -238,6 +239,7 @@ format_object2(const char *format, const char **last, const void *object,
 			}
 
 			/* fall through */
+			gcc_fallthrough;
 
 		default:
 			/* pass-through non-escaped portions of the format string */