]> Savannah Git Hosting - gnulib.git/commitdiff
nullptr: test for compilers at autoconf-time
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 8 Feb 2023 04:37:09 +0000 (20:37 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Wed, 8 Feb 2023 04:37:34 +0000 (20:37 -0800)
* 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
m4/nullptr.m4

index 624afb7e95b35be70c983b5e13a21f47b492e167..09317e6b89be3ddf059988f13d9f14c35c3d2ffa 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2023-02-07  Paul Eggert  <eggert@cs.ucla.edu>
 
+       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.
index dda7646906e323c213fa0b72928c6240e4015720..a0b438be941d621d23257c98804b475cb0fcf7b9 100644 (file)
@@ -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
 ])