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.
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
])