On OpenBSD 6.0, I'm seeing this compilation error: depbase=`echo test-sched-c++.o | sed 's|[^/]*$|.deps/&|;s|\.o$||'`;\ g++ -DHAVE_CONFIG_H -DEXEEXT=\"\" -I. -I../../gltests -I.. -DGNULIB_STRICT_CHECKING=1 -DIN_GNULIB_TESTS=1 -I. -I../../gltests -I.. -I../../gltests/.. -I../gllib -I../../gltests/../gllib -I/home/bruno/include -Wall -Wno-error -g -O2 -MT test-sched-c++.o -MD -MP -MF $depbase.Tpo -c -o test-sched-c++.o ../../gltests/test-sched-c++.cc &&\ mv -f $depbase.Tpo $depbase.Po In file included from /usr/include/pthread.h:47, from ../gllib/pthread.h:46, from ../gllib/signal.h:68, from ../gllib/sys/select.h:119, from /usr/include/sys/types.h:230, from ../gllib/sys/types.h:39, from /usr/include/sched.h:42, from ../gllib/sched.h:30, from ../../gltests/test-sched-c++.cc:22: ../gllib/sched.h: In member function 'gnulib::_gl_sched_yield_wrapper::operator int (*)()() const': ../gllib/sched.h:566: error: '::sched_yield' has not been declared gmake[4]: *** [Makefile:23347: test-sched-c++.o] Error 1
The problem here is not that sched_yield is not declared, but rather that its declaration comes too late, due to the sequence of #includes. sched_yield is declared at /usr/include/sched.h:65 and used at gllib/sched.h:566. test-sched-c++.cc:22 -> ../gllib/sched.h ../gllib/sched.h:30 -> /usr/include/sched.h /usr/include/sched.h:42 -> ../gllib/sys/types.h ../gllib/sys/types.h:39 -> /usr/include/sys/types.h /usr/include/sys/types.h:230 -> ../gllib/sys/select.h ../gllib/sys/select.h:119 -> ../gllib/signal.h <-- HERE1 ../gllib/signal.h:68 -> ../gllib/pthread.h <-- HERE2 ../gllib/pthread.h:46 -> /usr/include/pthread.h /usr/include/pthread.h:47 -> ./gllib/sched.h ../gllib/sched.h:30 -> /usr/include/sched.h declares sched_yield The natural places to cut down the #include forest is at HERE1 or HERE2. And indeed the one at HERE2 is not needed any more in OpenBSD ≥ 5.1. Thus, this patch fixes the issue. 2022-09-18 Bruno Haible <br...@clisp.org> signal: Fix a C++ compilation error due to sched_yield on OpenBSD 6.0. * lib/signal.in.h: On OpenBSD, include <sys/param.h>. Don't include <pthread.h> on OpenBSD ≥ 5.1. diff --git a/lib/signal.in.h b/lib/signal.in.h index 5d2d80c99d..c0d4848db0 100644 --- a/lib/signal.in.h +++ b/lib/signal.in.h @@ -55,12 +55,19 @@ #ifndef _@GUARD_PREFIX@_SIGNAL_H #define _@GUARD_PREFIX@_SIGNAL_H -/* Mac OS X 10.3, FreeBSD < 8.0, OpenBSD 3.8, OSF/1 4.0, Solaris 2.6, Android, +/* For testing the OpenBSD version. */ +#if (@GNULIB_PTHREAD_SIGMASK@ || defined GNULIB_POSIXCHECK) \ + && defined __OpenBSD__ +# include <sys/param.h> +#endif + +/* Mac OS X 10.3, FreeBSD < 8.0, OpenBSD < 5.1, OSF/1 4.0, Solaris 2.6, Android, OS/2 kLIBC declare pthread_sigmask in <pthread.h>, not in <signal.h>. But avoid namespace pollution on glibc systems.*/ #if (@GNULIB_PTHREAD_SIGMASK@ || defined GNULIB_POSIXCHECK) \ && ((defined __APPLE__ && defined __MACH__) \ - || (defined __FreeBSD__ && __FreeBSD__ < 8) || defined __OpenBSD__ \ + || (defined __FreeBSD__ && __FreeBSD__ < 8) \ + || (defined __OpenBSD__ && OpenBSD < 201205) \ || defined __osf__ || defined __sun || defined __ANDROID__ \ || defined __KLIBC__) \ && ! defined __GLIBC__