maint: remove unnecessary casts before using gnulib functions
[bison.git] / m4 / cxx.m4
blobcb6e9fcfda83432d76d50216c91a27dc1fbc8b32
1 # -*- Autoconf -*-
2 # Sanity-test a C++ compiler.
4 # Copyright (C) 2004, 2006, 2009-2015, 2018-2022 Free Software
5 # Foundation, Inc.
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
20 # Written by Paul Eggert.
22 AC_DEFUN([BISON_TEST_FOR_WORKING_CXX_COMPILER],
24  AC_CACHE_CHECK([whether $CXX builds executables that work],
25    bison_cv_cxx_works,
26    [AC_LANG_PUSH([C++])
27     bison_cv_cxx_works=no
28     AC_COMPILE_IFELSE(
29       [AC_LANG_PROGRAM(
30          [[
31           #include <cstdlib>
32           #include <iostream>
33           #include <map>
34           #include <string>
35           using namespace std;]],
36          [[std::cerr << "";
37           cout << "";
38           typedef std::pair<unsigned, int> uipair;
39           std::map<unsigned, int> m;
40           std::map<unsigned, int>::iterator i;
41           m.insert (uipair (4, -4));
42           for (i = m.begin (); i != m.end (); ++i)
43             if (i->first != 4)
44               return 1;]])],
45       [AS_IF([AC_TRY_COMMAND([$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_objext $LIBS >&AS_MESSAGE_LOG_FD])],
46          [AS_IF([test "$cross_compiling" = yes],
47             [bison_cv_cxx_works=cross],
48             [AS_IF([AC_TRY_COMMAND(./conftest$ac_exeext)],
49                [bison_cv_cxx_works=yes])])])
50        rm -f conftest$ac_exeext])
51     AC_LANG_POP([C++])])
53  case $bison_cv_cxx_works in
54    yes)        BISON_CXX_WORKS=':';;
55    no | cross) BISON_CXX_WORKS='false';;
56  esac
58  AC_SUBST([BISON_CXX_WORKS])
59  AM_CONDITIONAL([ENABLE_CXX], [test $bison_cv_cxx_works = yes])
62 # BISON_CXX_COMPILER_POSIXLY_CORRECT
63 # ----------------------------------
64 # Whether the C++ compiler supports -g in POSIXLY_CORRECT mode.
65 AC_DEFUN([BISON_CXX_COMPILER_POSIXLY_CORRECT],
66 [AC_LANG_PUSH([C++])
67 BISON_LANG_COMPILER_POSIXLY_CORRECT
68 AC_LANG_POP([C++])