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




commit 005b659b8617c6fd8379782509d5cbf442b7a6b5
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..52a64c9db 100644
--- a/glib/gmacros.h
+++ b/glib/gmacros.h
@@ -238,9 +238,11 @@
 #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>
 #define glib_typeof(t) typename std::remove_reference<decltype (t)>::type
 #define glib_typeof_2_68
+} /* extern "C++" */
 #endif
 
 /*


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