From cb2fcfc0a1da3cfac9094abf1d11c23653937395 Mon Sep 17 00:00:00 2001
From: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Date: Thu, 21 Sep 2017 13:36:42 +0200
Subject: Add no-return attribute to usage() style functions

A common pattern in command line processing is having a usage()
function that prints out how to use the command line options and
then terminates.

The function is typically used inside a switch block for command
line options like `-h' or unknown options. In a lot of places, the
break keyword is omitted, because the function exits anyway. However,
this triggers gcc warnings about implicit fall-through.

Rather than adding a phony "/* fall-through */" this patch flags the
usage() style function with a gcc attribute, indicating that they do
not return and removes further superfluous break statements.

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
---
 include/common.h | 7 +++++++
 1 file changed, 7 insertions(+)

(limited to 'include')

diff --git a/include/common.h b/include/common.h
index d609257..2ce5d22 100644
--- a/include/common.h
+++ b/include/common.h
@@ -129,6 +129,13 @@ extern "C" {
 	fprintf(stderr, "%s: warning!: " fmt "\n", PROGRAM_NAME, ##__VA_ARGS__); \
 } while(0)
 
+/* for tagging functions that always exit */
+#if defined(__GNUC__) || defined(__clang__)
+	#define NORETURN __attribute__((noreturn))
+#else
+	#define NORETURN
+#endif
+
 /**
  * prompt the user for confirmation
  */
-- 
cgit v1.2.3