1

最近、GLib を使用するアプリケーションの 1 つで次の警告に遭遇しました。

warning: ISO C prohibits argument conversion to union type [-Wpedantic]
note: in definition of macro '_G_DEFINE_BOXED_TYPE_BEGIN'
 2147 |     _g_register_boxed (g_intern_static_string (#TypeName), copy_func, free_func);

私は通常 でコンパイルします-wpedanticが、自分のコードまでたどることができないという警告が表示されたのは初めてでしたが、マクロの内部が原因のよう_G_DEFINE_BOXED_TYPE_BEGINです。G_DEFINE_BOXED_TYPEフリーやコピー専用の機能で使うと必ず警告が出るようです。

アプリケーションの例は次のようになります。

/* boxed_warning.c
 * Produces warning, when compiled with:
 * $ cc `pkg-config --cflags glib-2.0` -Wextra -Wpedantic -Wall -std=gnu11 -O0 -g -o 'boxed_warning.c.o' -c boxed_warning.c
 */
#include <glib.h>
#include <gio/gio.h>

struct _FooBoxed { gdouble x; };
typedef struct _FooBoxed FooBoxed;

static FooBoxed *
foo_boxed_copy (const FooBoxed *boxed)
{
  FooBoxed *result = g_new (FooBoxed, 1);
  *result = *boxed;
  return result;
}

G_DEFINE_BOXED_TYPE (FooBoxed, foo_boxed, (GBoxedCopyFunc) foo_boxed_copy, (GBoxedFreeFunc) g_free)

glib 2.62.4 を使用していますが、git.gnome.org の最新バージョンでコンパイルしても警告を再現できます。

GLib2.0 を使用しているときにこの警告を経験し、回避策を見つけた人はいますか? それとも、警告は実際に私のコードによる言及されたマクロの間違った使用法に関連していますか?

4

0 に答える 0