[2.6.4 clang/glibc-2.25.90] implicit declaration of function 'reallocarray' is invalid in C99
When built with clang-4.0.1, on system with glibc-2.25.90 (glibc 2.26 development snapshot, current git master), the following is noted during compilation
https://gist.github.com/elkrejzi/baad3a9c0035ef954cbb8e6ce2d635ba
At runtime, while compiling doxygen, flex will crash with the following backtrace
https://gist.github.com/elkrejzi/2f821eab0346ea1d1501dfd0f8c53195
Glibc 2.26 will have reallocarray function:
https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=2e0bbbfbf95fc9e22692e93658a6fbdd2d4554da;hp=4f26ef1b67287d1f2c32865f7d79c13abda81915
reallocarray is declared in malloc.h on glibc-based system. Simply adding "#include <malloc.h>" to src/flexdef.h fixes the problem for me.
@elkrejzi reallocarray prototypes in FreeBSD and OpenBSD are defined in <stdlib.h> (see man pages 1 2 ) Glibc should follow and declare reallocarray prototype in <stdlib.h> as well. Since you're building against a development version of Glibc, there's nothing we could fix in flex's side.
@Explorer09 It's unlikely glibc is going to change their behaviour. This is after all, a non-standard function.
According to https://sourceware.org/bugzilla/show_bug.cgi?id=21789 you need to define _GNU_SOURCE on glibc systems to use this function via stdlib.h (well, as I said, it's a non-standard function).
@elkrejzi I would say thank you for finding that out.
However regarding feature test macros, flex misses many of them, not just _GNU_SOURCE.
The current flex source can pop out many "implicit declaration" warnings when built with gcc -std=c99.
I think that's another issue different from this one.
Well, clang defaults to c99 mode for some time now. Doesn't gcc as well?
Yes, but that is a different issue than this one.
On Wednesday, 19 July 2017, 1:01 pm +0000, elkrejzi [email protected] wrote:
Well, clang defaults to c99 mode for some time now. Doesn't gcc as well?
-- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/westes/flex/issues/241#issuecomment-316378513
-- Will Estes [email protected]
@elkrejzi I mean c99 mode without GNU extensions
I just needed to build lede/openwrt on manjaro; fixed it by adding this patch to tools/flex/patches/:
https://github.com/westes/flex/commit/24fd0551333e7eded87b64dd36062da3df2f6380.patch