A couple of .h substitute modules omit the .h file when the system header file is present and correct. But the GNULIB_NAMESPACE support is, of course, not present in the system header, therefore this leads to a compilation failure in a testdir that was built with --with-c++-tests (even on glibc systems). Such as:
In file included from ../../gltests/test-fnmatch-h-c++.cc:24:0: ../../gltests/test-fnmatch-h-c++.cc:19:26: error: ‘gnulib’ has not been declared #define GNULIB_NAMESPACE gnulib ^ ../../gltests/signature.h:46:58: note: in definition of macro ‘SIGNATURE_CHECK2’ static ret (* _GL_UNUSED signature_check ## id) args = fn ^ ../../gltests/signature.h:39:3: note: in expansion of macro ‘SIGNATURE_CHECK1’ SIGNATURE_CHECK1 (fn, ret, args, __LINE__) ^ ../../gltests/test-fnmatch-h-c++.cc:28:1: note: in expansion of macro ‘SIGNATURE_CHECK’ SIGNATURE_CHECK (GNULIB_NAMESPACE::fnmatch, int, ^ ../../gltests/test-fnmatch-h-c++.cc:28:18: note: in expansion of macro ‘GNULIB_NAMESPACE’ SIGNATURE_CHECK (GNULIB_NAMESPACE::fnmatch, int, ^ ../../gltests/signature.h:46:28: warning: ‘signature_check29’ defined but not used [-Wunused-variable] static ret (* _GL_UNUSED signature_check ## id) args = fn ^ ../../gltests/signature.h:44:3: note: in expansion of macro ‘SIGNATURE_CHECK2’ SIGNATURE_CHECK2 (fn, ret, args, id) /* macroexpand line */ ^ ../../gltests/signature.h:39:3: note: in expansion of macro ‘SIGNATURE_CHECK1’ SIGNATURE_CHECK1 (fn, ret, args, __LINE__) ^ ../../gltests/test-fnmatch-h-c++.cc:28:1: note: in expansion of macro ‘SIGNATURE_CHECK’ SIGNATURE_CHECK (GNULIB_NAMESPACE::fnmatch, int, ^ This patch fixes it. 2018-08-06 Bruno Haible <br...@clisp.org> Force generation of substitute .h file when C++ support is enabled. * m4/ansi-c++.m4 (gl_ANSI_CXX): New macro. * modules/ansi-c++-opt (configure.ac): Just require gl_ANSI_CXX. * m4/fnmatch_h.m4 (gl_FNMATCH_H): If C++ support is enabled, set FNMATCH_H to non-empty. * m4/iconv_h.m4 (gl_ICONV_H_DEFAULTS): If C++ support is enabled, set ICONV_H to non-empty. * m4/monetary_h.m4 (gl_MONETARY_H_BODY): If C++ support is enabled, set MONETARY_H to non-empty. * m4/utime_h.m4 (gl_UTIME_H): If C++ support is enabled, set UTIME_H to non-empty. diff --git a/m4/ansi-c++.m4 b/m4/ansi-c++.m4 index 0cabd34..9eb362c 100644 --- a/m4/ansi-c++.m4 +++ b/m4/ansi-c++.m4 @@ -1,4 +1,4 @@ -# ansi-c++.m4 serial 9 +# ansi-c++.m4 serial 10 dnl Copyright (C) 2002-2003, 2005, 2010-2018 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -126,3 +126,13 @@ EOF AM_CONDITIONAL([am__fastdepCXX], [false]) fi ]) + +# gl_ANSI_CXX +# Sets CXX to the name of a sufficiently ANSI C++ compliant compiler, or to +# "no" if none is found. +# Defines the Automake condition ANSICXX to true if such a compiler was found, +# or to false if not. +AC_DEFUN([gl_ANSI_CXX], +[ + gl_PROG_ANSI_CXX([CXX], [ANSICXX]) +]) diff --git a/modules/ansi-c++-opt b/modules/ansi-c++-opt index 719c076..176f174 100644 --- a/modules/ansi-c++-opt +++ b/modules/ansi-c++-opt @@ -7,7 +7,7 @@ m4/ansi-c++.m4 Depends-on: configure.ac: -gl_PROG_ANSI_CXX([CXX], [ANSICXX]) +AC_REQUIRE([gl_ANSI_CXX]) Makefile.am: diff --git a/m4/fnmatch_h.m4 b/m4/fnmatch_h.m4 index a5a1aa2..c40d0a7 100644 --- a/m4/fnmatch_h.m4 +++ b/m4/fnmatch_h.m4 @@ -1,4 +1,4 @@ -# fnmatch_h.m4 serial 1 +# fnmatch_h.m4 serial 2 dnl Copyright (C) 2009-2018 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -9,6 +9,7 @@ dnl From Bruno Haible. AC_DEFUN([gl_FNMATCH_H], [ AC_REQUIRE([gl_FNMATCH_H_DEFAULTS]) + m4_ifdef([gl_ANSI_CXX], [AC_REQUIRE([gl_ANSI_CXX])]) AC_CHECK_HEADERS_ONCE([fnmatch.h]) gl_CHECK_NEXT_HEADERS([fnmatch.h]) @@ -28,9 +29,14 @@ AC_DEFUN([gl_FNMATCH_H], m4_ifdef([gl_POSIXCHECK], [FNMATCH_H=fnmatch.h], [FNMATCH_H='' - if test $ac_cv_header_fnmatch_h != yes; then - dnl Provide a substitute <fnmatch.h> file. + if m4_ifdef([gl_ANSI_CXX], [test "$CXX" != no], [false]); then + dnl Override <fnmatch.h> always, to support the C++ GNULIB_NAMESPACE. FNMATCH_H=fnmatch.h + else + if test $ac_cv_header_fnmatch_h != yes; then + dnl Provide a substitute <fnmatch.h> file. + FNMATCH_H=fnmatch.h + fi fi ]) AC_SUBST([FNMATCH_H]) diff --git a/m4/iconv_h.m4 b/m4/iconv_h.m4 index 918969e..253c008 100644 --- a/m4/iconv_h.m4 +++ b/m4/iconv_h.m4 @@ -1,4 +1,4 @@ -# iconv_h.m4 serial 10 +# iconv_h.m4 serial 11 dnl Copyright (C) 2007-2018 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -36,6 +36,7 @@ AC_DEFUN([gl_ICONV_MODULE_INDICATOR], AC_DEFUN([gl_ICONV_H_DEFAULTS], [ + m4_ifdef([gl_ANSI_CXX], [AC_REQUIRE([gl_ANSI_CXX])]) GNULIB_ICONV=0; AC_SUBST([GNULIB_ICONV]) dnl Assume proper GNU behavior unless another module says otherwise. ICONV_CONST=; AC_SUBST([ICONV_CONST]) @@ -43,6 +44,12 @@ AC_DEFUN([gl_ICONV_H_DEFAULTS], REPLACE_ICONV_OPEN=0; AC_SUBST([REPLACE_ICONV_OPEN]) REPLACE_ICONV_UTF=0; AC_SUBST([REPLACE_ICONV_UTF]) ICONV_H=''; AC_SUBST([ICONV_H]) - m4_ifdef([gl_POSIXCHECK],[ICONV_H='iconv.h']) + m4_ifdef([gl_POSIXCHECK], + [ICONV_H='iconv.h'], + [if m4_ifdef([gl_ANSI_CXX], [test "$CXX" != no], [false]); then + dnl Override <fnmatch.h> always, to support the C++ GNULIB_NAMESPACE. + ICONV_H='iconv.h' + fi + ]) AM_CONDITIONAL([GL_GENERATE_ICONV_H], [test -n "$ICONV_H"]) ]) diff --git a/m4/monetary_h.m4 b/m4/monetary_h.m4 index 0866b80..887ed91 100644 --- a/m4/monetary_h.m4 +++ b/m4/monetary_h.m4 @@ -1,4 +1,4 @@ -# monetary_h.m4 serial 2 +# monetary_h.m4 serial 3 dnl Copyright (C) 2017-2018 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -14,11 +14,14 @@ AC_DEFUN([gl_MONETARY_H], AC_DEFUN([gl_MONETARY_H_BODY], [ AC_REQUIRE([gl_MONETARY_H_DEFAULTS]) + m4_ifdef([gl_ANSI_CXX], [AC_REQUIRE([gl_ANSI_CXX])]) AC_CHECK_HEADERS_ONCE([monetary.h]) - dnl For now, we provide a <monetary.h> wrapper only if the system already - dnl has a <monetary.h>. - if m4_ifdef([gl_POSIXCHECK],[true],[test $ac_cv_header_monetary_h = yes]); then + dnl For now, we provide a <monetary.h> wrapper only if + dnl - module 'posixcheck' is present, or + dnl - C++ GNULIB_NAMESPACE support may be requested, or + dnl - the system already has a <monetary.h>. + if m4_ifdef([gl_POSIXCHECK], [true], [m4_ifdef([gl_ANSI_CXX], [test "$CXX" != no], [false]) || test $ac_cv_header_monetary_h = yes]); then MONETARY_H='monetary.h' gl_CHECK_NEXT_HEADERS([monetary.h]) diff --git a/m4/utime_h.m4 b/m4/utime_h.m4 index ab459fe..89a9981 100644 --- a/m4/utime_h.m4 +++ b/m4/utime_h.m4 @@ -1,4 +1,4 @@ -# utime_h.m4 serial 2 +# utime_h.m4 serial 3 dnl Copyright (C) 2017-2018 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -10,6 +10,7 @@ AC_DEFUN([gl_UTIME_H], [ AC_REQUIRE([AC_CANONICAL_HOST]) AC_REQUIRE([gl_UTIME_H_DEFAULTS]) + m4_ifdef([gl_ANSI_CXX], [AC_REQUIRE([gl_ANSI_CXX])]) AC_CHECK_HEADERS_ONCE([utime.h]) gl_CHECK_NEXT_HEADERS([utime.h]) @@ -23,15 +24,20 @@ AC_DEFUN([gl_UTIME_H], m4_ifdef([gl_POSIXCHECK], [UTIME_H=utime.h], [UTIME_H='' - if test $ac_cv_header_utime_h != yes; then - dnl Provide a substitute <utime.h> file. + if m4_ifdef([gl_ANSI_CXX], [test "$CXX" != no], [false]); then + dnl Override <utime.h> always, to support the C++ GNULIB_NAMESPACE. UTIME_H=utime.h else - case "$host_os" in - mingw*) dnl Need special handling of 'struct utimbuf'. - UTIME_H=utime.h - ;; - esac + if test $ac_cv_header_utime_h != yes; then + dnl Provide a substitute <utime.h> file. + UTIME_H=utime.h + else + case "$host_os" in + mingw*) dnl Need special handling of 'struct utimbuf'. + UTIME_H=utime.h + ;; + esac + fi fi ]) AC_SUBST([UTIME_H])