This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

static_assert in c89 and c99


In our sources in pre c11 we add our own assert.h and use #include_next
to get the proper one after having added a couple of things of our own.

One of those things is a static_assert defined when not compiling with
-std=c11, if c11 we want the one provided by glibcs assert.h.

test snippet:

--------------
#include <assert.h>

#ifdef static_assert
#error static_assert defined
#endif
--------------

gcc -D_GNU_SOURCE -std=c89 -c snippet.c
gcc -D_GNU_SOURCE -std=c99 -c snippet.c
gcc -D_GNU_SOURCE -std=c11 -c snippet.c

all error out, where only c11 variant is expected to do so.

It seems that the addition of "# define _ISOC11_SOURCE 1" (features.h)
to what gets defined by _GNU_SOURCE is causing this.

In assert.h static_assert is always defined when __USE_ISOC11 is defined
and that is unconditionally defined by _ISOC11_SOURCE. For a library
feature that would be ok, but since static_assert is using
_Static_assert its usability is really controlled by the compiler and
-std=c11.

I think the static_assert define must be guarded by a check that
-std=c11 really is in effect.

This is with glibc 2.20, this used to work nicely with 2.14 or
thereabouts.

-- 
	Lgb


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]