升级到glib-2.44后出现奇怪的警告

时间:2015-03-29 09:08:47

标签: c gtk3 glib

升级到Glib-2.44后,当我尝试编译软件时收到这些警告:

In file included from /usr/include/glib-2.0/gobject/gobject.h:24:0,
                 from /usr/include/glib-2.0/gobject/gbinding.h:29,
                 from /usr/include/glib-2.0/glib-object.h:23,
                 from /usr/include/glib-2.0/gio/gioenums.h:28,
                 from /usr/include/glib-2.0/gio/giotypes.h:28,
                 from /usr/include/glib-2.0/gio/gio.h:26,
                 from /usr/include/gtk-3.0/gdk/gdkapplaunchcontext.h:28,
                 from /usr/include/gtk-3.0/gdk/gdk.h:32,
                 from /usr/include/gtk-3.0/gtk/gtk.h:30,
                 from src/get_file_size.c:1:
/usr/include/glib-2.0/gio/glistmodel.h: In function ‘G_LIST_MODEL’:
/usr/include/glib-2.0/gobject/gtype.h:2186:40: warning: cast discards ‘const’ qualifier from pointer target type [-Wcast-qual]
     ((ct*) g_type_check_instance_cast ((GTypeInstance*) ip, gt))
                                        ^
/usr/include/glib-2.0/gobject/gtype.h:479:66: note: in expansion of macro ‘_G_TYPE_CIC’
 #define G_TYPE_CHECK_INSTANCE_CAST(instance, g_type, c_type)    (_G_TYPE_CIC ((instance), (g_type), c_type))
                                                                  ^
/usr/include/glib-2.0/gobject/gtype.h:1565:12: note: in expansion of macro ‘G_TYPE_CHECK_INSTANCE_CAST’
     return G_TYPE_CHECK_INSTANCE_CAST (ptr, module_obj_name##_get_type (), ModuleObjName); }               \
            ^
/usr/include/glib-2.0/gio/glistmodel.h:36:1: note: in expansion of macro ‘G_DECLARE_INTERFACE’
 G_DECLARE_INTERFACE(GListModel, g_list_model, G, LIST_MODEL, GObject)
 ^
/usr/include/glib-2.0/gio/glistmodel.h: In function ‘G_IS_LIST_MODEL’:
/usr/include/glib-2.0/gobject/gtype.h:2200:27: warning: cast discards ‘const’ qualifier from pointer target type [-Wcast-qual]
   GTypeInstance *__inst = (GTypeInstance*) ip; GType __t = gt; gboolean __r; \
                           ^
/usr/include/glib-2.0/gobject/gtype.h:491:66: note: in expansion of macro ‘_G_TYPE_CIT’
 #define G_TYPE_CHECK_INSTANCE_TYPE(instance, g_type)            (_G_TYPE_CIT ((instance), (g_type)))
                                                                  ^
/usr/include/glib-2.0/gobject/gtype.h:1567:12: note: in expansion of macro ‘G_TYPE_CHECK_INSTANCE_TYPE’
     return G_TYPE_CHECK_INSTANCE_TYPE (ptr, module_obj_name##_get_type ()); }                              \
            ^
/usr/include/glib-2.0/gio/glistmodel.h:36:1: note: in expansion of macro ‘G_DECLARE_INTERFACE’
 G_DECLARE_INTERFACE(GListModel, g_list_model, G, LIST_MODEL, GObject)
 ^
/usr/include/glib-2.0/gio/glistmodel.h: In function ‘G_LIST_MODEL_GET_IFACE’:
/usr/include/glib-2.0/gobject/gtype.h:2196:72: warning: cast discards ‘const’ qualifier from pointer target type [-Wcast-qual]
 #define _G_TYPE_IGI(ip, gt, ct)         ((ct*) g_type_interface_peek (((GTypeInstance*) ip)->g_class, gt))
                                                                        ^
/usr/include/glib-2.0/gobject/gtype.h:533:66: note: in expansion of macro ‘_G_TYPE_IGI’
 #define G_TYPE_INSTANCE_GET_INTERFACE(instance, g_type, c_type) (_G_TYPE_IGI ((instance), (g_type), c_type))
                                                                  ^
/usr/include/glib-2.0/gobject/gtype.h:1569:12: note: in expansion of macro ‘G_TYPE_INSTANCE_GET_INTERFACE’
     return G_TYPE_INSTANCE_GET_INTERFACE (ptr, module_obj_name##_get_type (), ModuleObjName##Interface); } \
            ^
/usr/include/glib-2.0/gio/glistmodel.h:36:1: note: in expansion of macro ‘G_DECLARE_INTERFACE’
 G_DECLARE_INTERFACE(GListModel, g_list_model, G, LIST_MODEL, GObject)
 ^
/usr/include/glib-2.0/gio/gliststore.h: In function ‘G_LIST_STORE’:
/usr/include/glib-2.0/gobject/gtype.h:2186:40: warning: cast discards ‘const’ qualifier from pointer target type [-Wcast-qual]
     ((ct*) g_type_check_instance_cast ((GTypeInstance*) ip, gt))
                                        ^
/usr/include/glib-2.0/gobject/gtype.h:479:66: note: in expansion of macro ‘_G_TYPE_CIC’
 #define G_TYPE_CHECK_INSTANCE_CAST(instance, g_type, c_type)    (_G_TYPE_CIC ((instance), (g_type), c_type))
                                                                  ^
/usr/include/glib-2.0/gobject/gtype.h:1396:12: note: in expansion of macro ‘G_TYPE_CHECK_INSTANCE_CAST’
     return G_TYPE_CHECK_INSTANCE_CAST (ptr, module_obj_name##_get_type (), ModuleObjName); }             \
            ^
/usr/include/glib-2.0/gio/gliststore.h:36:1: note: in expansion of macro ‘G_DECLARE_FINAL_TYPE’
 G_DECLARE_FINAL_TYPE(GListStore, g_list_store, G, LIST_STORE, GObject)
 ^
/usr/include/glib-2.0/gio/gliststore.h: In function ‘G_IS_LIST_STORE’:
/usr/include/glib-2.0/gobject/gtype.h:2200:27: warning: cast discards ‘const’ qualifier from pointer target type [-Wcast-qual]
   GTypeInstance *__inst = (GTypeInstance*) ip; GType __t = gt; gboolean __r; \
                           ^
/usr/include/glib-2.0/gobject/gtype.h:491:66: note: in expansion of macro ‘_G_TYPE_CIT’
 #define G_TYPE_CHECK_INSTANCE_TYPE(instance, g_type)            (_G_TYPE_CIT ((instance), (g_type)))
                                                                  ^
/usr/include/glib-2.0/gobject/gtype.h:1398:12: note: in expansion of macro ‘G_TYPE_CHECK_INSTANCE_TYPE’
     return G_TYPE_CHECK_INSTANCE_TYPE (ptr, module_obj_name##_get_type ()); }                            \
            ^
/usr/include/glib-2.0/gio/gliststore.h:36:1: note: in expansion of macro ‘G_DECLARE_FINAL_TYPE’
 G_DECLARE_FINAL_TYPE(GListStore, g_list_store, G, LIST_STORE, GObject)

这是函数的源代码(我也从其他不同函数收到相同的警告,这是其中之一):

#include <gtk/gtk.h>
#include <glib.h>
#include <glib/gstdio.h>

goffset
get_file_size (const gchar *file_path)
{
    GFileInfo *info;
    GFile *file;
    GError *error = NULL;
    const gchar *attributes = "standard::*";
    GFileQueryInfoFlags flags = G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS;
    GCancellable *cancellable = NULL;
    goffset file_size;

    file = g_file_new_for_path (file_path);
    info = g_file_query_info (file, attributes, flags, cancellable, &error);
    file_size = g_file_info_get_size (info);

    g_object_unref(file);

    return file_size;
}

我知道我可以使用-Wno-cast-qual来避免它们,但我不想这样做。使用Glib-2.42我没有遇到这些问题 我无法理解如何解决此警告,因为我没有在特定的代码上收到它 有什么想法吗?

1 个答案:

答案 0 :(得分:1)

警告来自重新定义GIO本身内部的GListStoreGListModel结构,而不是来自您的代码。这是有效的C11,并且对于最新版本的GCC有效,但是较旧的编译器会发出警告。

This issue最近在GLib中得到了修复,一旦它被释放,警告将在GLib 2.44.1中消失。