From 97f54920a3c2bd9a536ef8c1cb7667584bd84eaf Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 7 Feb 2023 20:37:09 -0800 Subject: [PATCH 3/3] nullptr: test for compilers at autoconf-time * m4/nullptr.m4 (gl_NULLPTR): Test for C and C++ compiler usage at autoconf-time. This should work better than testing at configure-time. Also, push and pop languages so we check the proper compiler. --- ChangeLog | 6 ++++++ m4/nullptr.m4 | 28 +++++++++++++++++++--------- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 624afb7e95..09317e6b89 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2023-02-07 Paul Eggert + nullptr: test for compilers at autoconf-time + * m4/nullptr.m4 (gl_NULLPTR): Test for C and C++ compiler usage at + autoconf-time. This should work better than testing at + configure-time. Also, push and pop languages so we check the + proper compiler. + nullptr: test for C++ nullptr at configure-time * m4/nullptr.m4 (gl_NULLPTR): Test for C++ support for nullptr at configure-time, as we already do for C support. diff --git a/m4/nullptr.m4 b/m4/nullptr.m4 index dda7646906..a0b438be94 100644 --- a/m4/nullptr.m4 +++ b/m4/nullptr.m4 @@ -7,22 +7,32 @@ dnl with or without modifications, as long as this notice is preserved. AC_DEFUN([gl_NULLPTR], [ - AS_IF([test ${CC+set}], - [AC_CACHE_CHECK([for C nullptr], [gl_cv_c_nullptr], + m4_provide_if([AC_PROG_CC], + [AC_LANG_PUSH([C]) + AC_CACHE_CHECK([for C nullptr], [gl_cv_c_nullptr], [AC_COMPILE_IFELSE( [AC_LANG_SOURCE([[int *p = nullptr;]])], [gl_cv_c_nullptr=yes], - [gl_cv_c_nullptr=no])])]) - if test "$gl_cv_c_nullptr" = yes; then - AC_DEFINE([HAVE_C_NULLPTR], [1], [Define to 1 if C nullptr works.]) + [gl_cv_c_nullptr=no])]) + gl_c_nullptr=$gl_cv_c_nullptr + AC_LANG_POP([C])], + [gl_c_nullptr=no]) + if test "$gl_c_nullptr" = yes; then + AC_DEFINE([HAVE_C_NULLPTR], [1], + [Define to 1 if C nullptr is known to work.]) fi - AS_IF([test ${CXX+set}], - [AC_CACHE_CHECK([for C++ nullptr], [gl_cv_cxx_nullptr], + + m4_provide_if([AC_PROG_CXX], + [AC_LANG_PUSH([C++]) + AC_CACHE_CHECK([for C++ nullptr], [gl_cv_cxx_nullptr], [AC_COMPILE_IFELSE( [AC_LANG_SOURCE([[int *p = nullptr;]])], [gl_cv_cxx_nullptr=yes], - [gl_cv_cxx_nullptr=no])])]) - if test "$gl_cv_cxx_nullptr" = yes; then + [gl_cv_cxx_nullptr=no])]) + gl_cxx_nullptr=$gl_cv_cxx_nullptr + AC_LANG_POP([C++])], + [gl_cxx_nullptr=no]) + if test "$gl_cxx_nullptr" = yes; then AC_DEFINE([HAVE_CXX_NULLPTR], [1], [Define to 1 if C++ nullptr works.]) fi ]) -- 2.39.1