[glib/wip/kalev/decltype-extern-Cplusplus] gmacros: Guard C++ code with extern "C++"




commit f1b9302a1eba9aa277ecff74653b1e5d2ad3f45e
Author: Kalev Lember <klember redhat com>
Date:   Mon Feb 8 16:36:13 2021 +0100

    gmacros: Guard C++ code with extern "C++"
    
    A number of C++ consumers are (incorrectly) including glib headers in an
    extern "C" block, which leads to build failures such as:
    
    /usr/include/c++/11/type_traits:56:3: error: template with C linkage
       56 |   template<typename _Tp, _Tp __v>
          |   ^~~~~~~~
    
    We can easily escape that on the glib side by putting the C++ code in an
    extern "C++" block. Which technically it's a bug on the consuming
    program's side, I think it's pragmatic here to work this around on the
    glib side.

 glib/gmacros.h | 2 ++
 1 file changed, 2 insertions(+)
---
diff --git a/glib/gmacros.h b/glib/gmacros.h
index ca1ecbd0a..404537621 100644
--- a/glib/gmacros.h
+++ b/glib/gmacros.h
@@ -238,7 +238,9 @@
 #define glib_typeof(t) __typeof__ (t)
 #elif defined(__cplusplus) && __cplusplus >= 201103L
 /* C++11 decltype() is close enough for our usage */
+extern "C++" {
 #include <type_traits>
+} /* extern "C++" */
 #define glib_typeof(t) typename std::remove_reference<decltype (t)>::type
 #define glib_typeof_2_68
 #endif


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