GNOME Bugzilla – Bug 660413
Make G_ASSERT_STATIC work with clang
Last modified: 2011-10-05 17:40:17 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 */
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.
This patch causes the build to fail with gcc: gmappedfile.c:93:2: error: variably modified '_GStaticAssertCompileTimeAssertion_93' at file scope
Created attachment 198226 [details] [review] Make G_ASSERT_STATIC work with clang A simplified variant of an approach proposed by Behdad.
Attachment 198226 [details] pushed as e517fb6 - Make G_ASSERT_STATIC work with clang Will cherry-pick to glib-2-30 as well.
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.
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.
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 on attachment 198353 [details] [review] gmacros: Hide G_STATIC_ASSERT from g-ir-scanner No harm here.
Attachment 198353 [details] pushed as c3133af - gmacros: Hide G_STATIC_ASSERT from g-ir-scanner