summaryrefslogtreecommitdiff
path: root/m4/nullptr.m4
blob: 1f8ab51b8548f505b675d1dd226598ba1037436f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# Check for nullptr that conforms to C23 and C++11.

dnl Copyright 2023 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.

AC_DEFUN([gl_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])])
      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

  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],
          [AC_COMPILE_IFELSE(
             [AC_LANG_SOURCE([[#include <stddef.h>
                               int *p = nullptr;]])],
             [gl_cv_cxx_nullptr="yes, but it is a <stddef.h> macro"],
             [gl_cv_cxx_nullptr=no])])])
     AS_CASE([$gl_cv_cxx_nullptr],
       [yes],  [gl_have_cxx_nullptr=1],
       [yes*], [gl_have_cxx_nullptr="(-1)"],
               [gl_have_cxx_nullptr=0])
     AC_DEFINE_UNQUOTED([HAVE_CXX_NULLPTR], [$gl_have_cxx_nullptr],
                        [Define to 1 if C++ nullptr works, 0 if not,
                         (-1) if it is a <stddef.h> macro.])
     AC_LANG_POP([C++])])
])

  AH_VERBATIM([zznullptr],
[#if defined __cplusplus && HAVE_CXX_NULLPTR < 0
# include <stddef.h>
# undef/**/nullptr
#endif
#ifndef nullptr
# if !defined __cplusplus && !defined HAVE_C_NULLPTR
#  define nullptr ((void *) 0)
# elif defined __cplusplus && HAVE_CXX_NULLPTR <= 0
#  if 3 <= __GNUG__
#   define nullptr __null
#  else
#   define nullptr 0L
#  endif
# endif
#endif])
])