From 36db8e32d5d64af651b6fba16f349323fa2cde8e Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Fri, 26 Jul 2024 13:04:09 +0200 Subject: [PATCH] sys_un: Avoid compilation error in C++ on glibc systems. * m4/sys_un_h.m4 (gl_SYS_UN_H): Require AC_CANONICAL_HOST. Set GL_GENERATE_SYS_UN_H to true on glibc systems. Invoke gl_CHECK_NEXT_HEADERS. Initialize HAVE_SYS_UN_H. * lib/sys_un.in.h: Use include_next and a split double-inclusion guard. In C++ mode, include and first. * modules/sys_un (Depends-on): Add include_next. (Makefile.am): Substitute INCLUDE_NEXT, PRAGMA_SYSTEM_HEADER, PRAGMA_COLUMNS, NEXT_SYS_UN_H, HAVE_SYS_UN_H. Arrange to remove 'sys' directory at "make mostlyclean". --- ChangeLog | 13 +++++++++++++ lib/sys_un.in.h | 42 ++++++++++++++++++++++++++++++++++++------ m4/sys_un_h.m4 | 35 ++++++++++++++++++++++++++--------- modules/sys_un | 9 ++++++++- 4 files changed, 83 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2f2a949b77..a9fa667880 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2024-07-26 Bruno Haible + + sys_un: Avoid compilation error in C++ on glibc systems. + * m4/sys_un_h.m4 (gl_SYS_UN_H): Require AC_CANONICAL_HOST. Set + GL_GENERATE_SYS_UN_H to true on glibc systems. Invoke + gl_CHECK_NEXT_HEADERS. Initialize HAVE_SYS_UN_H. + * lib/sys_un.in.h: Use include_next and a split double-inclusion guard. + In C++ mode, include and first. + * modules/sys_un (Depends-on): Add include_next. + (Makefile.am): Substitute INCLUDE_NEXT, PRAGMA_SYSTEM_HEADER, + PRAGMA_COLUMNS, NEXT_SYS_UN_H, HAVE_SYS_UN_H. Arrange to remove 'sys' + directory at "make mostlyclean". + 2024-07-26 Bruno Haible xstrtol, xstrtoll tests: Improve comment. diff --git a/lib/sys_un.in.h b/lib/sys_un.in.h index 52993d65f5..c137e7cef4 100644 --- a/lib/sys_un.in.h +++ b/lib/sys_un.in.h @@ -18,17 +18,47 @@ /* Written by Collin Funk. */ #ifndef _@GUARD_PREFIX@_SYS_UN_H -#define _@GUARD_PREFIX@_SYS_UN_H 1 -/* Windows requires to be included before . */ -#if @HAVE_WINSOCK2_H@ -# include +#if __GNUC__ >= 3 +@PRAGMA_SYSTEM_HEADER@ #endif -#if @HAVE_AFUNIX_H@ -# include +@PRAGMA_COLUMNS@ + +#if @HAVE_SYS_UN_H@ + +/* On glibc, in C++ mode with clang, and need to be + included before , because otherwise includes them inside + an 'extern "C" { ... }' block, which leads to compilation errors in gnulib's + override. */ +# if defined __cplusplus +# include +# include +# endif + +/* The include_next requires a split double-inclusion guard. */ +# @INCLUDE_NEXT@ @NEXT_SYS_UN_H@ + #endif +#ifndef _@GUARD_PREFIX@_SYS_UN_H +#define _@GUARD_PREFIX@_SYS_UN_H 1 + +#if !@HAVE_SYS_UN_H@ + +/* A platform that lacks . */ + +/* Windows requires to be included before . */ +# if @HAVE_WINSOCK2_H@ +# include +# endif +# if @HAVE_AFUNIX_H@ +# include +# endif + /* If a platform does not support AF_UNIX sockets 'struct sockaddr_un' will not be defined. You may use HAVE_UNIXSOCKET after including . */ #endif + +#endif /* _@GUARD_PREFIX@_SYS_UN_H */ +#endif /* _@GUARD_PREFIX@_SYS_UN_H */ diff --git a/m4/sys_un_h.m4 b/m4/sys_un_h.m4 index ed19b70cb5..959cd86c0a 100644 --- a/m4/sys_un_h.m4 +++ b/m4/sys_un_h.m4 @@ -1,5 +1,5 @@ # sys_un_h.m4 -# serial 1 +# serial 2 dnl Copyright 2024 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -7,26 +7,43 @@ dnl with or without modifications, as long as this notice is preserved. AC_DEFUN_ONCE([gl_SYS_UN_H], [ + AC_REQUIRE([AC_CANONICAL_HOST]) + dnl Check if UNIX domain sockets are supported. AC_REQUIRE([gl_SOCKET_FAMILY_UNIX]) GL_GENERATE_SYS_UN_H=false - if test $gl_cv_socket_unix = yes; then - dnl Check if using a Windows version that supports AF_UNIX. dnl See . if test "$ac_cv_header_winsock2_h" = yes \ && test "$ac_cv_header_afunix_h" = yes; then GL_GENERATE_SYS_UN_H=true fi + case "$host_os" in + dnl On glibc systems, we need to include before , + dnl at least in C++ mode with clang. + *-gnu* | gnu*) GL_GENERATE_SYS_UN_H=true ;; + esac fi - dnl Checked in gl_SOCKET_FAMILY_UNIX. - if test "$ac_cv_header_afunix_h" = yes; then - HAVE_AFUNIX_H=1 - else - HAVE_AFUNIX_H=0 + if $GL_GENERATE_SYS_UN_H; then + AC_CHECK_HEADERS([sys/un.h]) + gl_CHECK_NEXT_HEADERS([sys/un.h]) + + if test $ac_cv_header_sys_un_h = yes; then + HAVE_SYS_UN_H=1 + else + HAVE_SYS_UN_H=0 + fi + AC_SUBST([HAVE_SYS_UN_H]) + + dnl Checked in gl_SOCKET_FAMILY_UNIX. + if test "$ac_cv_header_afunix_h" = yes; then + HAVE_AFUNIX_H=1 + else + HAVE_AFUNIX_H=0 + fi + AC_SUBST([HAVE_AFUNIX_H]) fi - AC_SUBST([HAVE_AFUNIX_H]) ]) diff --git a/modules/sys_un b/modules/sys_un index af72a80aab..21505946a8 100644 --- a/modules/sys_un +++ b/modules/sys_un @@ -7,6 +7,7 @@ m4/sys_un_h.m4 Depends-on: gen-header +include_next sys_socket configure.ac: @@ -24,15 +25,21 @@ sys/un.h: sys_un.in.h $(top_builddir)/config.status @NMD@ $(AM_V_GEN)$(MKDIR_P) '%reldir%' $(gl_V_at)$(SED_HEADER_STDOUT) \ -e 's|@''GUARD_PREFIX''@|${gl_include_guard_prefix}|g' \ + -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ + -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ + -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ + -e 's|@''NEXT_SYS_UN_H''@|$(NEXT_SYS_UN_H)|g' \ + -e 's|@''HAVE_SYS_UN_H''@|$(HAVE_SYS_UN_H)|g' \ -e 's|@''HAVE_WINSOCK2_H''@|$(HAVE_WINSOCK2_H)|g' \ -e 's|@''HAVE_AFUNIX_H''@|$(HAVE_AFUNIX_H)|g' \ - $(srcdir)/sys_un.in.h > $@-t + $(srcdir)/sys_un.in.h > $@-t $(AM_V_at)mv $@-t $@ else sys/un.h: $(top_builddir)/config.status rm -f $@ endif MOSTLYCLEANFILES += sys/un.h sys/un.h-t +MOSTLYCLEANDIRS += sys Include: -- 2.39.5