After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 744473 - including <gio/gio.h> causes "redefinition of typedef" compile warning
including <gio/gio.h> causes "redefinition of typedef" compile warning
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: gio
2.43.x
Other Mac OS
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
: 744485 746694 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2015-02-13 15:17 UTC by Young Han Lee
Modified: 2017-09-11 15:26 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Young Han Lee 2015-02-13 15:17:02 UTC
#include <gio/gio.h>

int main() {
  return 0;
}


On mac, compiling above code with latest xcode causes typedef compiler warning as following;


In file included from /mypath/install/include/glib-2.0/gio/gio.h:163:
/mypath/install/include/glib-2.0/gio/glistmodel.h:36:21: warning: 
      redefinition of typedef 'GListModel' is a C11 feature
      [-Wtypedef-redefinition]
G_DECLARE_INTERFACE(GListModel, g_list_model, G, LIST_MODEL, GObject)
                    ^
/mypath/install/include/glib-2.0/gobject/gtype.h:1559:35: note: 
      expanded from macro 'G_DECLARE_INTERFACE'
  typedef struct _##ModuleObjName ModuleObjName...
                                  ^
/mypath/install/include/glib-2.0/gio/giotypes.h:64:47: note: 
      previous definition is here
typedef struct _GListModel                    GListModel;
                          

Here is my gcc version information;

$ gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin14.1.0
Thread model: posix
Comment 1 Young Han Lee 2015-02-13 15:41:52 UTC
Redefinition of typedef is illegal in C.

Do we need to put a definition check in G_DECLARE_FINAL_TYPE ?
Comment 2 Emmanuele Bassi (:ebassi) 2015-02-13 15:48:12 UTC
(In reply to Young Han Lee from comment #1)
> Redefinition of typedef is illegal in C.

no, it's not illegal in C11 and it has been a GCC extension before that.
Comment 3 Young Han Lee 2015-02-13 16:13:57 UTC
(In reply to Emmanuele Bassi (:ebassi) from comment #2) 
> no, it's not illegal in C11 and it has been a GCC extension before that.

You're right. It would be better to use -Wno-typedef-redefinition option in this case. Thanks.
Comment 4 Emmanuele Bassi (:ebassi) 2015-02-13 16:20:00 UTC
I did not close the bug report on purpose, in case there's something GLib can do to avoid the warning.
Comment 5 Sebastian Dröge (slomo) 2015-02-16 08:39:39 UTC
*** Bug 744485 has been marked as a duplicate of this bug. ***
Comment 6 Ryan Schmidt 2015-03-06 09:37:53 UTC
glib 2.43.91 cannot be compiled on OS X 10.6 or earlier (which use Apple's gcc 4.2.1 or earlier) because:

In file included from ../../gio/gio.h:164,
                 from kqueue-exclusions.c:26:
../../gio/glistmodel.h:36: error: redefinition of typedef 'GListModel'
../../gio/giotypes.h:64: error: previous declaration of 'GListModel' was here
In file included from ../../gio/gio.h:165,
                 from kqueue-exclusions.c:26:
../../gio/gliststore.h:36: error: redefinition of typedef 'GListStore'
../../gio/giotypes.h:65: error: previous declaration of 'GListStore' was here
Comment 7 Antoine Jacoutot 2015-03-24 16:04:34 UTC
*** Bug 746694 has been marked as a duplicate of this bug. ***
Comment 8 Antoine Jacoutot 2015-03-24 16:05:35 UTC
FWIW, same error happens on OpenBSD.
Comment 9 Antoine Jacoutot 2015-03-25 06:48:17 UTC
Just to extend on my former comment.
As is, GLib is now impossible to build on OpenBSD (gcc 4.2.1).
If I use another compiler,
Comment 10 Antoine Jacoutot 2015-03-25 06:51:48 UTC
Oops, pressed a key to fast.

So as I was saying...
As is, GLib is now impossible to build by default on OpenBSD (gcc 4.2.1).
If I use a newer compiler (e.g. gcc 4.8) then I can build it *but* anything depending on GLib/gio will not be able to build unless I also use a newer compiler to build them. Since the default compiler on OpenBSD is gcc 4.2.1, this is not really acceptable for us to use an external gcc to build 1000 packages from our ports tree.

Could the GLib team revisit this change so that it works with not-too-modern compilers?
Thanks.
Comment 11 Antoine Jacoutot 2015-03-25 15:38:10 UTC
Issue fixed with this GLib commit:
4a292721bcf2943bfc05c6a1c859992f28e3efec