bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Fix a compilation error in C++ mode on FreeBSD 13.1


From: Bruno Haible
Subject: Fix a compilation error in C++ mode on FreeBSD 13.1
Date: Sun, 04 Sep 2022 02:03:40 +0200

On FreeBSD 13.1, a C++ test fails:

depbase=`echo test-sched-c++.o | sed 's|[^/]*$|.deps/&|;s|\.o$||'`;\
c++ -ferror-limit=0 -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 
-I/usr/local/include -Wall -D_THREAD_SAFE  -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 ../../gltests/test-sched-c++.cc:22:
In file included from ../gllib/sched.h:30:
In file included from /usr/include/sched.h:33:
In file included from ../gllib/sys/types.h:39:
In file included from /usr/include/sys/types.h:376:
In file included from ../gllib/sys/select.h:89:
In file included from ../gllib/sys/time.h:39:
In file included from /usr/include/sys/time.h:592:
In file included from ../gllib/sys/select.h:118: -- avoid?
In file included from ../gllib/signal.h:67:
In file included from ../gllib/pthread.h:46:
In file included from /usr/include/pthread.h:48:
../gllib/sched.h:566:19: error: no member named 'sched_yield' in the global 
namespace
_GL_CXXALIAS_SYS (sched_yield, int, (void));
~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
../gllib/time.h:264:20: note: expanded from macro '_GL_CXXALIAS_SYS'
          return ::func;                                      \
                 ~~^
1 error generated.

So, we have a sequence of nested includes
  <sched.h> -> <sys/types.h> -> <sys/select.h> -> <sys/time.h> -> <sys/select.h>
   -> <signal.h> -> <pthread.h> -> <sched.h>

There are two obvious ways to stop this sequence: On FreeBSD,
  - <sys/select.h> -> <sys/time.h> is unnecessary,
  - <signal.h> -> <pthread.h> is unnecessary.
Removing the <signal.h> -> <pthread.h> include fixes the compilation error.
Removing, additionally, the <sys/select.h> -> <sys/time.h> include does
not hurt.


2022-09-03  Bruno Haible  <bruno@clisp.org>

        Fix a compilation error in C++ mode on FreeBSD 13.1.
        * lib/signal.in.h: Don't include <pthread.h> on FreeBSD ≥ 8.0.
        * lib/sys_select.in.h: Don't include <sys/time.h> on FreeBSD.

diff --git a/lib/signal.in.h b/lib/signal.in.h
index 640b5022f5..5d2d80c99d 100644
--- a/lib/signal.in.h
+++ b/lib/signal.in.h
@@ -55,13 +55,14 @@
 #ifndef _@GUARD_PREFIX@_SIGNAL_H
 #define _@GUARD_PREFIX@_SIGNAL_H
 
-/* Mac OS X 10.3, FreeBSD 6.4, OpenBSD 3.8, OSF/1 4.0, Solaris 2.6, Android,
+/* Mac OS X 10.3, FreeBSD < 8.0, OpenBSD 3.8, 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__ || defined __OpenBSD__ || defined __osf__ \
-        || defined __sun || defined __ANDROID__ || defined __KLIBC__) \
+        || (defined __FreeBSD__ && __FreeBSD__ < 8) || defined __OpenBSD__ \
+        || defined __osf__ || defined __sun || defined __ANDROID__ \
+        || defined __KLIBC__) \
     && ! defined __GLIBC__
 # include <pthread.h>
 #endif
diff --git a/lib/sys_select.in.h b/lib/sys_select.in.h
index 2bd0e0f79a..b424f1b803 100644
--- a/lib/sys_select.in.h
+++ b/lib/sys_select.in.h
@@ -82,9 +82,10 @@
    of 'struct timeval', and no definition of this type.
    Also, Mac OS X, AIX, HP-UX, IRIX, Solaris, Interix declare select()
    in <sys/time.h>.
-   But avoid namespace pollution on glibc systems and "unknown type
-   name" problems on Cygwin.  */
-# if !(defined __GLIBC__ || defined __CYGWIN__)
+   But avoid namespace pollution on glibc systems, a circular include
+   <sys/select.h> -> <sys/time.h> -> <sys/select.h> on FreeBSD 13.1, and
+   "unknown type name" problems on Cygwin.  */
+# if !(defined __GLIBC__ || defined __FreeBSD__ || defined __CYGWIN__)
 #  include <sys/time.h>
 # endif
 






reply via email to

[Prev in Thread] Current Thread [Next in Thread]