1 # bison-cxx-std.m4 serial 1
3 # Copyright (C) 2018-2021 Free Software Foundation, Inc.
5 # This file is free software; the Free Software Foundation
6 # gives unlimited permission to copy and/or distribute it,
7 # with or without modifications, as long as this notice is preserved.
9 m4_define([_BISON_CXXSTD_98_snippet],
12 typedef std::vector<int> ints;
15 m4_define([_BISON_CXXSTD_03_snippet],
18 m4_define([_BISON_CXXSTD_11_snippet],
29 static_assert(sizeof(int) <= sizeof(T), "not big enough");
32 using right_angle_brackets = check<check<bool>>;
34 auto f = std::make_shared<std::string>("shared_ptr");
39 typedef check<int> check_type;
41 check_type&& cr = static_cast<check_type&&>(c);
45 // Some versions of libstdc++ do not support std::set::emplace.
52 // Clang++ 3.5, for a while, was unable to process properly
53 // the for-loop because its variable, r, is a typedef...
54 // It failed as follows:
56 // error: unexpected ':' in nested name specifier; did you mean '::'?
57 // for (auto r: std::set<int>{1, 2})
60 using r = std::set<int>;
63 for (int r: std::set<int>{1, 2})
67 // GCC 4.8.2 on Solaris 11.3 does not support to_string.
68 auto e = std::to_string(42);
71 m4_define([_BISON_CXXSTD_14_snippet],
75 using ints = std::vector<int>;
76 auto v1 = ints{1, 2, 3};
78 std::mismatch(std::begin(v1), std::end(v1),
79 std::begin(v2), std::end(v2));
83 m4_define([_BISON_CXXSTD_17_snippet],
85 namespace ns1::ns2::ns3 {}
88 auto opt_string = std::optional<std::string>{};
89 auto out = std::ostringstream{};
92 m4_define([_BISON_CXXSTD_2A_snippet],
97 m4_define([_BISON_CXXSTD_testbody(98)],
99 _BISON_CXXSTD_98_snippet
102 m4_define([_BISON_CXXSTD_testbody(03)],
104 _BISON_CXXSTD_98_snippet
105 _BISON_CXXSTD_03_snippet
108 m4_define([_BISON_CXXSTD_testbody(11)],
110 _BISON_CXXSTD_98_snippet
111 _BISON_CXXSTD_03_snippet
112 _BISON_CXXSTD_11_snippet
115 m4_define([_BISON_CXXSTD_testbody(14)],
117 _BISON_CXXSTD_98_snippet
118 _BISON_CXXSTD_03_snippet
119 _BISON_CXXSTD_11_snippet
120 _BISON_CXXSTD_14_snippet
123 m4_define([_BISON_CXXSTD_testbody(17)],
125 _BISON_CXXSTD_98_snippet
126 _BISON_CXXSTD_03_snippet
127 _BISON_CXXSTD_11_snippet
128 _BISON_CXXSTD_14_snippet
129 _BISON_CXXSTD_17_snippet
132 m4_define([_BISON_CXXSTD_testbody(2a)],
134 _BISON_CXXSTD_98_snippet
135 _BISON_CXXSTD_03_snippet
136 _BISON_CXXSTD_11_snippet
137 _BISON_CXXSTD_14_snippet
138 _BISON_CXXSTD_17_snippet
139 _BISON_CXXSTD_2A_snippet
143 m4_define([_BISON_CXXSTD_testbody],
145 [m4_indir([$0($1)], m4_shift2($@))],
146 [m4_fatal([$0: unknown C++ standard: $1])])])
151 # Check whether the C++ compiler support STD (11, 98, 2a, etc.).
152 # If it does, AC_SUBST 'CXX<STD>_CXXFLAGS' to the corresponding flags.
153 AC_DEFUN([BISON_CXXSTD],
154 [AC_REQUIRE([AC_PROG_CXX])
156 for f in '-std=c++$1' '-std=c++$1 -stdlib=libc++'
158 BISON_CHECK_COMPILER_FLAG([$f],
159 [AC_SUBST(m4_toupper([CXX$1_CXXFLAGS]), [$f]) break],
161 [_BISON_CXXSTD_testbody($1)])