summaryrefslogtreecommitdiff
path: root/m4
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2023-02-07 20:37:09 -0800
committerPaul Eggert <eggert@cs.ucla.edu>2023-02-07 20:37:34 -0800
commit97f54920a3c2bd9a536ef8c1cb7667584bd84eaf (patch)
treeaf45b01ac9a437a9449ebbad9c2175e4fb8b587c /m4
parent7a5061a0527b9fcaeedf48e8f5056dd80e77aa98 (diff)
downloadgnulib-97f54920a3c2bd9a536ef8c1cb7667584bd84eaf.tar.gz
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.
Diffstat (limited to 'm4')
-rw-r--r--m4/nullptr.m428
1 files changed, 19 insertions, 9 deletions
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
])