http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52635

--- Comment #3 from Mikael Pettersson <mikpe at it dot uu.se> 2012-03-20 
17:26:23 UTC ---
(In reply to comment #2)
> Do you have an example not involving __builtin_constant_p?

Unfortunately no.  The example is just a cleaned up and reduced version of the
one from PR52632.  I've tried a few variations with __builtin_offsetof() and
sizeof(), but they all work, i.e., generate diagnostics at all optimization
levels.

>  When 
> optimizing, this array will be considered a VLA (i.e. the size will be 
> considered nonconstant) as __builtin_constant_p is only evaluated later 
> (after inlining, for example), long after decisions about whether arrays 
> are VLAs have to be made.

I see.  The Linux kernel also uses the following variation:

#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); })

which seems to work with all of __builtin_constant_p, __builtin_offsetof,
sizeof, at both -O0 and -O2.

Perhaps I ought to submit a kernel patch to make BUILD_BUG_ON() use the struct
trick rather than the array size trick?

Reply via email to