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 660413 - Make G_ASSERT_STATIC work with clang
Make G_ASSERT_STATIC work with clang
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2011-09-29 05:14 UTC by Behdad Esfahbod
Modified: 2011-10-05 17:40 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Make G_ASSERT_STATIC work with clang (1.06 KB, patch)
2011-10-04 15:53 UTC, Allison Karlitskaya (desrt)
committed Details | Review
gmacros: Hide G_STATIC_ASSERT from g-ir-scanner (1.28 KB, patch)
2011-10-05 16:20 UTC, Colin Walters
committed Details | Review

Description Behdad Esfahbod 2011-09-29 05:14:16 UTC
clang seems to be buggy with the way G_ASSERT_STATIC works.  I'm going to report that.  In the mean time, this change fixes that and is harmless otherwise:

--- /home/behdad/gnome/glib/glib/gmacros.h	2011-07-12 18:16:13.000000000 -0400
+++ gmacros.h	2011-09-28 17:13:30.000000000 -0400
@@ -146,7 +146,7 @@
 
 #define G_PASTE_ARGS(identifier1,identifier2) identifier1 ## identifier2
 #define G_PASTE(identifier1,identifier2)      G_PASTE_ARGS (identifier1, identifier2)
-#define G_STATIC_ASSERT(expr) typedef struct { char Compile_Time_Assertion[(expr) ? 1 : -1]; } G_PASTE (_GStaticAssert_, __LINE__)
+#define G_STATIC_ASSERT(expr) typedef char G_PASTE (_GStaticAssertCompileTimeAssertion_, __LINE__)[(G_STATIC_ASSERT_EXPR (expr), 1)]
 #define G_STATIC_ASSERT_EXPR(expr) ((void) sizeof (char[(expr) ? 1 : -1]))
 
 /* Provide a string identifying the current code position */
Comment 1 Behdad Esfahbod 2011-09-29 18:26:40 UTC
Seems like clang is actually following the word of the standard:

http://llvm.org/bugs/show_bug.cgi?id=11036

So, fix in glib is appreciated.
Comment 2 Allison Karlitskaya (desrt) 2011-10-04 15:49:42 UTC
This patch causes the build to fail with gcc:

gmappedfile.c:93:2: error: variably modified '_GStaticAssertCompileTimeAssertion_93' at file scope
Comment 3 Allison Karlitskaya (desrt) 2011-10-04 15:53:28 UTC
Created attachment 198226 [details] [review]
Make G_ASSERT_STATIC work with clang

A simplified variant of an approach proposed by Behdad.
Comment 4 Allison Karlitskaya (desrt) 2011-10-04 15:56:42 UTC
Attachment 198226 [details] pushed as e517fb6 - Make G_ASSERT_STATIC work with clang

Will cherry-pick to glib-2-30 as well.
Comment 5 Colin Walters 2011-10-05 16:20:08 UTC
Created attachment 198353 [details] [review]
gmacros: Hide G_STATIC_ASSERT from g-ir-scanner

The C syntax here is twisted and confuses the scanner.  We don't
need to see it, so let's just skip it.
Comment 6 Colin Walters 2011-10-05 16:21:15 UTC
This regressed gobject-introspection, and sorry it'd just be painful to fix there, and I'd rather keep glib working with older g-i's since this is a simple enough patch.
Comment 7 Emmanuele Bassi (:ebassi) 2011-10-05 16:24:13 UTC
I do wonder if we shouldn't just hide most of the non-trivial macros from the g-i scanner. it's not like I expect people to start using them from anything — even Vala.
Comment 8 Allison Karlitskaya (desrt) 2011-10-05 17:27:45 UTC
Comment on attachment 198353 [details] [review]
gmacros: Hide G_STATIC_ASSERT from g-ir-scanner

No harm here.
Comment 9 Colin Walters 2011-10-05 17:40:15 UTC
Attachment 198353 [details] pushed as c3133af - gmacros: Hide G_STATIC_ASSERT from g-ir-scanner