Re: [PATCH] utilize _Static_assert() for BUILD_BUG_ON() when thecompiler supports it

From: Daniel Santos
Date: Thu Dec 13 2012 - 16:20:02 EST


On 12/13/2012 03:43 AM, Jan Beulich wrote:
On 13.12.12 at 01:29, Daniel Santos<danielfsantos@xxxxxxx> wrote:
Wow, it's really easy to miss parallel development on the same issue.
Sorry for my late response to this thread. I started another thread
addressing these issues (as well as a few others) back in September
(https://lkml.org/lkml/2012/9/28/1136). I've finally gotten ACKs from
maintainers with v6 of the patches (here
https://lkml.org/lkml/2012/11/20/621) and I'm just waiting for 3.8-rc1
to re-submit them. I actually submitted these patches back in June as
part of a larger patch set, but broke it apart in September (I had way
to many changes for one patch set)
Since yours is apparently ready to go in, but doesn't use
_Static_assert, I guess I'll wait for it to appear until I re-work
whatever might be left to actually make use of _Static_assert.

Jan

Interesting! They've enabled it by default (I suppose as an extension?) in every standard (except -pedantic of course). One minor draw-back is that it appears to enjoy escaping tickmarks in the error message. I've opened a bug for it (http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55678)

But realistically, the "compiletime_assert" macro I wrote in compiler.h can be renamed to "static_assert", analogous to C11's static_assert from assert.h (§7.2 of C11) and it can expand to the _Static_assert keyword, when that is available.

Something else that I didn't consider too much before was support for compiling -O0 or -O1, which will cause many expressions that are otherwise evaluated as compile-time constants to become non-constant and result in failed assertions. This isn't anything new however, building -O0 has been broken for quite some time, but I presume it could help some development of out of tree modules.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/