summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2018-09-02 20:46:19 +0200
committerBenjamin Otte <otte@redhat.com>2018-09-04 20:24:21 +0200
commit95477a4e35b6726c2fa564a7d836943d3127adf8 (patch)
tree92648ccb89da958ad1cb6177e1905ce67f4ef366
parentb0e239c26eeda81ac212068c86adc7a8c40530b4 (diff)
downloadglib-95477a4e35b6726c2fa564a7d836943d3127adf8.tar.gz
macros: Add G_GNUC_FALLTHROUGH
Expands to the GNU C fallthrough statement attribute if the compiler is gcc. This allows declaring case statement to explicitly fall through in switch statements. To enable this feature, use -Wimplicit-fallthrough during compilation.
-rw-r--r--docs/reference/glib/glib-sections.txt1
-rw-r--r--glib/docs.c16
-rw-r--r--glib/gmacros.h6
3 files changed, 23 insertions, 0 deletions
diff --git a/docs/reference/glib/glib-sections.txt b/docs/reference/glib/glib-sections.txt
index 8c733e0aa..5f049cfcb 100644
--- a/docs/reference/glib/glib-sections.txt
+++ b/docs/reference/glib/glib-sections.txt
@@ -438,6 +438,7 @@ G_GNUC_DEPRECATED_FOR
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
G_GNUC_END_IGNORE_DEPRECATIONS
G_GNUC_NORETURN
+G_GNUC_FALLTHROUGH
G_GNUC_UNUSED
G_GNUC_PRINTF
G_GNUC_SCANF
diff --git a/glib/docs.c b/glib/docs.c
index 23ef41916..5212bb582 100644
--- a/glib/docs.c
+++ b/glib/docs.c
@@ -2281,6 +2281,22 @@
*/
/**
+ * G_GNUC_FALLTHROUGH:
+ *
+ * Expands to the GNU C fallthrough statement attribute if the compiler is gcc.
+ * This allows declaring case statement to explicitly fall through in switch
+ * statements. To enable this feature, use -Wimplicit-fallthrough during
+ * compilation.
+ *
+ * Put the attribute right before the case statement you want to fall through
+ * to.
+ *
+ * See the GNU C documentation for more details.
+ *
+ * Since: 2.60
+ */
+
+/**
* G_GNUC_UNUSED:
*
* Expands to the GNU C unused function attribute if the compiler is gcc.
diff --git a/glib/gmacros.h b/glib/gmacros.h
index 9b8ef0e89..0432d9cad 100644
--- a/glib/gmacros.h
+++ b/glib/gmacros.h
@@ -191,6 +191,12 @@
#define G_GNUC_NO_INSTRUMENT
#endif /* !__GNUC__ */
+#if __GNUC__ > 6
+#define G_GNUC_FALLTHROUGH __attribute__((fallthrough))
+#else
+#define G_GNUC_FALLTHROUGH
+#endif /* __GNUC__ */
+
#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)
#define G_GNUC_DEPRECATED __attribute__((__deprecated__))
#else