[glib: 1/2] glib/gmacros.h: Move `<type_traits>` include to consumers




commit 552b8fd862061e74b5ad2ffe6a700f850a76f797
Author: Iain Lane <iainl gnome org>
Date:   Wed Feb 24 15:11:42 2021 +0000

    glib/gmacros.h: Move `<type_traits>` include to consumers
    
    When included inside an `extern "C"` block, this causes build failures
    that look something like:
    
      /usr/include/c++/10/type_traits:2930:3: error: template with C linkage
       2930 |   template<typename _Fn, typename... _Args>
            |   ^~~~~~~~
      ../../disas/arm-a64.cc:20:1: note: ‘extern "C"’ linkage started here
         20 | extern "C" {
            | ^~~~~~~~~~
    
    Commit 4273c43902a7e6b22cea0041436ee5715c93be76 made this opt in for
    projects which are defining `GLIB_VERSION_MIN_REQUIRED`, but the include
    of `<type_traits>` via `gmacros.h` was not included in this. If we move
    the include out to the places where `glib_typeof` is called, we can make
    it covered by this macro too, and save a few consumers from FTBFSing.
    
    That also means that, if you don't want to fix your use of the headers,
    and as long as this version is sufficient for you, a quick workaround is
    to define `GLIB_VERSION_MIN_REQUIRED` to `GLIB_VERSION_2_66` or lower.
    
    Suggested by Simon McVittie.
    
    Alternative to: https://gitlab.gnome.org/GNOME/glib/-/merge_requests/1935
    Fixes: https://gitlab.gnome.org/GNOME/glib/-/issues/2331

 glib/gatomic.h    | 5 +++++
 glib/gmacros.h    | 7 ++++++-
 glib/gmem.h       | 5 +++++
 glib/grcbox.h     | 5 +++++
 gobject/gobject.h | 5 +++++
 5 files changed, 26 insertions(+), 1 deletion(-)
---
diff --git a/glib/gatomic.h b/glib/gatomic.h
index 16e0c7298..a1545beb0 100644
--- a/glib/gatomic.h
+++ b/glib/gatomic.h
@@ -26,6 +26,11 @@
 
 #include <glib/gtypes.h>
 
+#if defined(glib_typeof_2_68) && GLIB_VERSION_MIN_REQUIRED >= GLIB_VERSION_2_68
+/* for glib_typeof */
+#include <type_traits>
+#endif
+
 G_BEGIN_DECLS
 
 GLIB_AVAILABLE_IN_ALL
diff --git a/glib/gmacros.h b/glib/gmacros.h
index ca1ecbd0a..2ece48ba0 100644
--- a/glib/gmacros.h
+++ b/glib/gmacros.h
@@ -238,7 +238,12 @@
 #define glib_typeof(t) __typeof__ (t)
 #elif defined(__cplusplus) && __cplusplus >= 201103L
 /* C++11 decltype() is close enough for our usage */
-#include <type_traits>
+/* This needs `#include <type_traits>`, but we have guarded this feature with a
+ * `GLIB_VERSION_MIN_REQUIRED >= GLIB_VERSION_2_68` check, and such a check
+ * cannot be enforced in this header due to include ordering requirements.
+ * Within GLib itself, which use `glib_typeof` need to add the include
+ * themselves. See other examples in GLib for how to do this.
+ */
 #define glib_typeof(t) typename std::remove_reference<decltype (t)>::type
 #define glib_typeof_2_68
 #endif
diff --git a/glib/gmem.h b/glib/gmem.h
index e2720c765..ccf477843 100644
--- a/glib/gmem.h
+++ b/glib/gmem.h
@@ -31,6 +31,11 @@
 
 #include <glib/gutils.h>
 
+#if defined(glib_typeof_2_68) && GLIB_VERSION_MIN_REQUIRED >= GLIB_VERSION_2_68
+/* for glib_typeof */
+#include <type_traits>
+#endif
+
 G_BEGIN_DECLS
 
 /**
diff --git a/glib/grcbox.h b/glib/grcbox.h
index 0eb80da12..47dfd488b 100644
--- a/glib/grcbox.h
+++ b/glib/grcbox.h
@@ -24,6 +24,11 @@
 
 #include <glib/gmem.h>
 
+#if defined(glib_typeof_2_68) && GLIB_VERSION_MIN_REQUIRED >= GLIB_VERSION_2_68
+/* for glib_typeof */
+#include <type_traits>
+#endif
+
 G_BEGIN_DECLS
 
 GLIB_AVAILABLE_IN_2_58
diff --git a/gobject/gobject.h b/gobject/gobject.h
index 2db5f2fff..125aed876 100644
--- a/gobject/gobject.h
+++ b/gobject/gobject.h
@@ -28,6 +28,11 @@
 #include        <gobject/gsignal.h>
 #include        <gobject/gboxed.h>
 
+#if defined(glib_typeof_2_68) && GLIB_VERSION_MIN_REQUIRED >= GLIB_VERSION_2_68
+/* for glib_typeof */
+#include <type_traits>
+#endif
+
 G_BEGIN_DECLS
 
 /* --- type macros --- */


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