Skip to content
This repository was archived by the owner on Oct 24, 2025. It is now read-only.

Commit 55d3a4c

Browse files
committed
Work around C++11 nullptr
Provide CXX11_NULLPTR autoconf macro
1 parent 61ac61a commit 55d3a4c

File tree

4 files changed

+81
-1
lines changed

4 files changed

+81
-1
lines changed

configure.ac

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ AC_TYPE_SIZE_T
4242
AC_FUNC_MALLOC
4343
AC_CHECK_FUNCS([floor getcwd strtol])
4444

45+
CXX11_NULLPTR
46+
4547
# Checks for testing.
4648
AC_ARG_ENABLE(tests, AS_HELP_STRING([--enable-tests], [enable testing the build]),
4749
[enable_tests="$enableval"], [enable_tests=no])

m4/cxx11_nullptr.m4

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#serial 1
2+
AC_DEFUN([CXX11_NULLPTR],
3+
[
4+
AC_REQUIRE([CXX11_STD_AVAILABLE])
5+
CXX11_STD_TRY([nullptr], [], [[char *s = nullptr;]],
6+
[ $cxx11_cv_prog_cxx_cxx11 ],
7+
[
8+
AC_DEFINE([HAVE_CXX11_NULLPTR],[1],
9+
[Define to 1 C++11 nullptr is available])
10+
],
11+
[])
12+
])

m4/cxx11_std_try.m4

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#serial 1
2+
# CXX11_STD_TRY(STANDARD, TEST-PROLOGUE, TEST-BODY, OPTION-LIST,
3+
# ACTION-IF-AVAILABLE, ACTION-IF-UNAVAILABLE)
4+
# ----------------------------------------------------------------
5+
# Check whether the C++ compiler accepts features of STANDARD (e.g
6+
# `cxx98', `cxx11') by trying to compile a program of TEST-PROLOGUE
7+
# and TEST-BODY. If this fails, try again with each compiler option
8+
# in the space-separated OPTION-LIST; if one helps, append it to CXX.
9+
# If eventually successful, run ACTION-IF-AVAILABLE, else
10+
# ACTION-IF-UNAVAILABLE.
11+
AC_DEFUN([_CXX11_STD_TRY],
12+
[
13+
AC_LANG_PUSH(C++)dnl
14+
AC_CACHE_VAL(cxx11_cv_prog_cxx_$1,
15+
[cxx11_cv_prog_cxx_$1=no
16+
cxx11_save_CXX=$CXX
17+
AC_LANG_CONFTEST([AC_LANG_PROGRAM([$2], [$3])])
18+
for cxx11_arg in $4
19+
do
20+
CXX="$cxx11_save_CXX $cxx11_arg"
21+
_AS_ECHO_N([$cxx11_arg ])
22+
AC_COMPILE_IFELSE([], [cxx11_cv_prog_cxx_$1=$cxx11_arg])
23+
test "x$cxx11_cv_prog_cxx_$1" != "xno" && break
24+
done
25+
rm -f conftest.$ac_ext
26+
CXX=$cxx11_save_CXX
27+
])# AC_CACHE_VAL
28+
cxx11_prog_cxx_stdcxx_options=
29+
case "x$cxx11_cv_prog_cxx_$1" in
30+
x)
31+
AC_MSG_RESULT([working as-is]) ;;
32+
xno)
33+
AC_MSG_RESULT([not working]) ;;
34+
*)
35+
cxx11_prog_cxx_stdcxx_options=" $cxx11_cv_prog_cxx_$1"
36+
CXX=$CXX$cxx11_prog_cxx_stdcxx_options
37+
AC_MSG_RESULT([working]) ;;
38+
esac
39+
AC_LANG_POP(C++)dnl
40+
])# _CXX11_STD_TRY
41+
AC_DEFUN([CXX11_STD_TRY],
42+
[
43+
AC_MSG_CHECKING([for $CXX option to enable ]m4_translit($1, [x], [+])[ feature])
44+
_CXX11_STD_TRY($1, $2, $3, ["" m4_expand($4)])
45+
AS_IF([test "x$cxx11_cv_prog_cxx_$1" != xno], [$5], [$6])
46+
])
47+
AC_DEFUN([CXX11_STD_AVAILABLE],
48+
[
49+
cxx11_save_CXX=$CXX
50+
AC_MSG_CHECKING([for $CXX to have C++11 rvalue references])
51+
_CXX11_STD_TRY([cxx11], [], [[double&& d = 2]],
52+
[[ -std=c++11 -std=c++0x -qlanglvl=extended0x -AA ]])
53+
CXX=$cxx11_save_CXX
54+
])

src/util.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,13 @@ namespace Sass {
107107

108108
// convert the extracted hex string to code point value
109109
// ToDo: Maybe we could do this without creating a substring
110+
#ifndef HAVE_CXX11_NULLPTR
111+
#define nullptr (char **)0
112+
#endif
110113
uint32_t cp = strtol(s.substr (i + 1, len - 1).c_str(), nullptr, 16);
114+
#ifndef HAVE_CXX11_NULLPTR
115+
#undef nullptr
116+
#endif
111117

112118
if (cp == 0) cp = 0xFFFD;
113119

@@ -401,7 +407,13 @@ namespace Sass {
401407

402408
// convert the extracted hex string to code point value
403409
// ToDo: Maybe we could do this without creating a substring
404-
uint32_t cp = strtol(s.substr (i + 1, len - 1).c_str(), nullptr, 16);
410+
#ifndef HAVE_CXX11_NULLPTR
411+
#define nullptr (char **)0
412+
#endif
413+
uint32_t cp = strtol(s.substr (i + 1, len - 1).c_str(), nullptr, 16);
414+
#ifndef HAVE_CXX11_NULLPTR
415+
#undef nullptr
416+
#endif
405417

406418
if (s[i + len] == ' ') ++ len;
407419

0 commit comments

Comments
 (0)