I'm trying to build wip/ocaml on NetBSD 9 amd64 and came across: gcc -c -O2 -fno-strict-aliasing -fwrapv -pthread -Wall -Wdeclaration-after-statement -Werror -fno-common -fexcess-precision=standard -fno-tree-vrp -fPIC -ffunction-sections -g -O2 -fPIC -D_FORTIFY_SOURCE=2 -I/usr/include -D_FILE_OFFSET_BITS=64 -DCAML_NAME_SPACE -DCAMLDLLIMPORT= -I/usr/include -o floats.b.o floats.c floats.c: In function 'caml_copysign': floats.c:1074:10: error: implicit declaration of function 'copysign' [-Werror=implicit-function-declaration] return copysign(x, y); ^~~~~~~~ floats.c:1074:10: error: incompatible implicit declaration of built-in function 'copysign' [-Werror] floats.c:1074:10: note: include '<math.h>' or provide a declaration of 'copysign' cc1: all warnings being treated as errors gmake[2]: *** [Makefile:366: floats.b.o] Error 1 I found that floats.c set visibility defines: /* Needed for uselocale */ #define _XOPEN_SOURCE 700 /* Needed for strtod_l */ #define _GNU_SOURCE and if I added _NETBSD_SOURCE the build succeeded. In general I have the attitude that most use of visibility defines are wrong because e.g. asking for _XOPEN_SOURCE 700 means that things not defined in that standard should be hidden, and thus other visibility defines must also be turned on, but perhaps this is not one of those cases. Looking, I find that POSIX says copysign is taken from C99 https://pubs.opengroup.org/onlinepubs/9699919799/ Looking in math.h, I find that the copysign decl is guarded with _NETBSD_SOURCE. However copysignf is not guarded. This test program results in a warning for copysign but not copysignf. Without _XOPEN_SOURCE, or with _NETBSD_SOURCE, it compiles cleanly. ---------------------------------------- #define _XOPEN_SOURCE 700 #include <math.h> int main(int argc, char **argv) { double a, x, y; float af, xf, yf; x = xf = 9.0; y = yf = -2.0; af = copysignf(xf, yf); a = copysign(x, y); return 0; } ---------------------------------------- cs.c: In function ‘main’: cs.c:15:7: warning: implicit declaration of function ‘copysign’ [-Wimplicit-function-declaration] a = copysign(x, y); ^~~~~~~~ cs.c:15:7: warning: incompatible implicit declaration of built-in function ‘copysign’ cs.c:15:7: note: include ‘<math.h>’ or provide a declaration of ‘copysign’ ---------------------------------------- So I conclude that math.h is buggy on NetBSD 9. But can I really be the first to notice?
Attachment:
signature.asc
Description: PGP signature