Skip to content

Backport Suppress -Wint-in-bool-context warning with G_DEFINE_INTERFACE and g++ to glib-2-58

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)
                    ^~~~~~~~~~~~~

Backport of !555 (merged).

Merge request reports

Loading