[systemd-devel] compile with clang broken
Lennart Poettering
lennart at poettering.net
Fri Aug 15 09:19:13 PDT 2014
On Fri, 15.08.14 17:22, Daniele Nicolodi (daniele at grinta.net) wrote:
>
> On 15/08/2014 16:30, David Herrmann wrote:
> > Ok, took me a while, but I now figured out how to cause compilation to
> > fail even in expressions that initialize types (_Static_assert is not
> > allowed there):
> > #define assert_const(expr)
> > ((void)(__builtin_types_compatible_p(int[(expr) ? 1 : -1], int[1])))
> >
> > Btw., I like that more than our current assert_cc() fallback. But I
> > leave it up to you to decide.
> >
> > Anyhow, I found a way to make CONST_MAX work:
> > #define CONST_MAX(_A, _B)
> > (__builtin_choose_expr(__builtin_constant_p(_A) &&
> > __builtin_constant_p(_B), ((_A) > (_B)) ? (_A) : (_B), (void)0))
> >
> > This will return (void) in case _A or _B is not constant. Works fine
> > on LLVM, I now have to test it on gcc. If it works, I will commit it
> > and fix resolvd.
>
> Hello,
>
> this may be completely stupid, but if the only use case you have for
> CONST_MAX() is for computing the size of a data structure, I find
> something like
>
> #define MAXSIZE(A, B) sizeof(union { __typeof(A) a; __typeof(B) b;})
>
> a little more clear and less magic, and I believe it has the same
> guarantees that the solution you found.
>
> In the specific case, the problematic line could then be written as:
>
> uint8_t buffer[CMSG_SPACE(MAXSIZE(struct in_pktinfo,
> struct in6_pktinfo)) \
> + EXTRA_CMSG_SPACE];
>
> which IMHO reads a bit better.
I'd be fine with that, if anyone wants to put together a patch...
Lennart
--
Lennart Poettering, Red Hat
More information about the systemd-devel
mailing list