[glib/wip/otte/fallthrough: 1/3] macros: Add G_GNUC_FALLTHROUGH



commit f6e23c8b296527d821a271b984ac76ffaae34d11
Author: Benjamin Otte <otte redhat com>
Date:   Sun Sep 2 20:46:19 2018 +0200

    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.

 docs/reference/glib/glib-sections.txt |  1 +
 gio/gliststore.c                      |  3 +--
 glib/docs.c                           | 16 ++++++++++++++++
 glib/gmacros.h                        |  6 ++++++
 4 files changed, 24 insertions(+), 2 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/gio/gliststore.c b/gio/gliststore.c
index c91dcb334..5b7d42678 100644
--- a/gio/gliststore.c
+++ b/gio/gliststore.c
@@ -486,8 +486,7 @@ g_list_store_splice (GListStore *store,
               return;
             }
 
-          it = g_sequence_insert_before (it, g_object_ref (additions[i]));
-          it = g_sequence_iter_next (it);
+          g_sequence_insert_before (it, g_object_ref (additions[i]));
         }
     }
 
diff --git a/glib/docs.c b/glib/docs.c
index 23ef41916..5212bb582 100644
--- a/glib/docs.c
+++ b/glib/docs.c
@@ -2280,6 +2280,22 @@
  * See the GNU C documentation for more details.
  */
 
+/**
+ * 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:
  *
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


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]