[glib/glib-2-58: 1/2] Suppress -Wint-in-bool-context warning with G_DEFINE_INTERFACE and g++



commit 32bdd718b3bccc03356a434e0c4c228db735dd6e
Author: Kouhei Sutou <kou clear-code com>
Date:   Thu Dec 20 11:24:53 2018 +0900

    Suppress -Wint-in-bool-context warning with G_DEFINE_INTERFACE and g++
    
    Note that it's not reported with gcc. It's only reported with g++.
    
    C++ code to reproduce this warning:
    
        #include <glib-object.h>
    
        G_BEGIN_DECLS
    
        #define GARROW_TYPE_FILE (garrow_file_get_type())
        G_DECLARE_INTERFACE(GArrowFile,
                            garrow_file,
                            GARROW,
                            FILE,
                            GObject)
    
        struct _GArrowFileInterface {
          GTypeInterface g_iface;
        };
    
        G_DEFINE_INTERFACE(GArrowFile,
                           garrow_file,
                           G_TYPE_OBJECT)
    
        static void
        garrow_file_default_init(GArrowFileInterface *iface)
        {
        }
    
        G_END_DECLS
    
    Build command line:
    
        % g++ -Wall -shared -o liba.so a.cpp $(pkg-config --cflags --libs gobject-2.0)
    
    Message:
    
        In file included from /tmp/local.glib/include/glib-2.0/gobject/gobject.h:24,
                         from /tmp/local.glib/include/glib-2.0/gobject/gbinding.h:29,
                         from /tmp/local.glib/include/glib-2.0/glib-object.h:23,
                         from a.cpp:1:
        a.cpp: In function 'GType garrow_file_get_type()':
        /tmp/local.glib/include/glib-2.0/gobject/gtype.h:219:50: warning: '<<' in boolean context, did you 
mean '<' ? [-Wint-in-bool-context]
         #define G_TYPE_MAKE_FUNDAMENTAL(x) ((GType) ((x) << G_TYPE_FUNDAMENTAL_SHIFT))
                                                     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
        /tmp/local.glib/include/glib-2.0/gobject/gtype.h:2026:11: note: in definition of macro 
'_G_DEFINE_INTERFACE_EXTENDED_BEGIN'
               if (TYPE_PREREQ) \
                   ^~~~~~~~~~~
        /tmp/local.glib/include/glib-2.0/gobject/gtype.h:1758:47: note: in expansion of macro 
'G_DEFINE_INTERFACE_WITH_CODE'
         #define G_DEFINE_INTERFACE(TN, t_n, T_P)      G_DEFINE_INTERFACE_WITH_CODE(TN, t_n, T_P, ;)
                                                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
        a.cpp:16:1: note: in expansion of macro 'G_DEFINE_INTERFACE'
         G_DEFINE_INTERFACE(GArrowFile,
         ^~~~~~~~~~~~~~~~~~
        /tmp/local.glib/include/glib-2.0/gobject/gtype.h:178:25: note: in expansion of macro 
'G_TYPE_MAKE_FUNDAMENTAL'
         #define G_TYPE_OBJECT   G_TYPE_MAKE_FUNDAMENTAL (20)
                                 ^~~~~~~~~~~~~~~~~~~~~~~
        a.cpp:18:20: note: in expansion of macro 'G_TYPE_OBJECT'
                            G_TYPE_OBJECT)
                            ^~~~~~~~~~~~~

 gobject/gtype.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
---
diff --git a/gobject/gtype.h b/gobject/gtype.h
index 77e22a0a9..0d366e67b 100644
--- a/gobject/gtype.h
+++ b/gobject/gtype.h
@@ -2023,7 +2023,7 @@ type_name##_get_type (void) \
                                        0, \
                                        (GInstanceInitFunc)NULL, \
                                        (GTypeFlags) 0); \
-      if (TYPE_PREREQ) \
+      if (TYPE_PREREQ != G_TYPE_INVALID) \
         g_type_interface_add_prerequisite (g_define_type_id, TYPE_PREREQ); \
       { /* custom code follows */
 #define _G_DEFINE_INTERFACE_EXTENDED_END()     \


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