commit bb4e8f81d5fffa10c9a6b5fba1c166803c641c8b
parent 57118884ad541bd9d585785d7723508aecd21db9
Author: vaplv <vaplv@free.fr>
Date: Tue, 18 Dec 2018 11:06:36 +0100
Add the FALLTHROUGH generic macro
Quiet the compiler warning on "switch/case" implicit fallthrough.
Diffstat:
3 files changed, 49 insertions(+), 1 deletion(-)
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
@@ -217,8 +217,9 @@ if(NOT NO_TEST)
new_test(test_library rsys)
new_test(test_list rsys)
new_test(test_logger rsys)
- new_test(test_mem_allocator rsys)
new_test(test_math ${MATH_LIB})
+ new_test(test_mem_allocator rsys)
+ new_test(test_misc)
new_test(test_quaternion rsys)
new_test(test_ref)
new_test(test_signal rsys)
diff --git a/src/rsys.h b/src/rsys.h
@@ -402,5 +402,15 @@ typedef int res_T;
#define END_DECLS
#endif
+#ifdef COMPILER_GCC
+ #if __GNUC__ >= 7
+ #define FALLTHROUGH __attribute__ ((fallthrough))
+ #else
+ #define FALLTHROUGH (void)0
+ #endif
+#else
+ #define FALLTHROUGH (void)0
+#endif
+
#endif /* RSYS_H */
diff --git a/src/test_misc.c b/src/test_misc.c
@@ -0,0 +1,37 @@
+/* Copyright (C) 2013-2018 Vincent Forest (vaplv@free.fr)
+ *
+ * The RSys library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * The RSys library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with the RSys library. If not, see <http://www.gnu.org/licenses/>. */
+
+#include "rsys.h"
+
+int
+main(int argc, char** argv)
+{
+ int i = 0;
+ (void)argv;
+
+#ifdef COMPILER_GCC
+ printf("GCC version: %d.%d.%d\n",
+ __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
+#endif
+
+ /* Test fallthrough warning */
+ switch(argc) {
+ case 2: ++i; FALLTHROUGH;
+ case 1: ++i; FALLTHROUGH;
+ case 0: ++i; break;
+ default: FATAL("Unreachable code.\n");
+ }
+ return 0;
+}