1 # bison-cxx-std.m4 serial 1
3 # Copyright (C) 2018-2022 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 m4_define([_BISON_CXXSTD_03_snippet],
15 m4_define([_BISON_CXXSTD_11_snippet],
23 #include <utility> // std::swap
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 void cxx11_vector_data ()
73 std::vector<int> ints;
74 ints.emplace_back (42);
75 assert (ints.data () == &ints[0]);
79 void cxx11_array_swap ()
81 int i0[4] = { 1, 2, 3, 4 };
82 int i1[4] = { 5, 6, 7, 8 };
87 m4_define([_BISON_CXXSTD_14_snippet],
91 using ints = std::vector<int>;
92 auto v1 = ints{1, 2, 3};
94 std::mismatch(std::begin(v1), std::end(v1),
95 std::begin(v2), std::end(v2));
99 m4_define([_BISON_CXXSTD_17_snippet],
101 namespace ns1::ns2::ns3 {}
104 auto opt_string = std::optional<std::string>{};
105 auto out = std::ostringstream{};
108 m4_define([_BISON_CXXSTD_20_snippet],
112 m4_define([_BISON_CXXSTD_2B_snippet],
117 m4_define([_BISON_CXXSTD_testbody(98)],
119 _BISON_CXXSTD_98_snippet
122 m4_define([_BISON_CXXSTD_testbody(03)],
124 _BISON_CXXSTD_98_snippet
125 _BISON_CXXSTD_03_snippet
128 m4_define([_BISON_CXXSTD_testbody(11)],
130 _BISON_CXXSTD_98_snippet
131 _BISON_CXXSTD_03_snippet
132 _BISON_CXXSTD_11_snippet
135 m4_define([_BISON_CXXSTD_testbody(14)],
137 _BISON_CXXSTD_98_snippet
138 _BISON_CXXSTD_03_snippet
139 _BISON_CXXSTD_11_snippet
140 _BISON_CXXSTD_14_snippet
143 m4_define([_BISON_CXXSTD_testbody(17)],
145 _BISON_CXXSTD_98_snippet
146 _BISON_CXXSTD_03_snippet
147 _BISON_CXXSTD_11_snippet
148 _BISON_CXXSTD_14_snippet
149 _BISON_CXXSTD_17_snippet
152 m4_define([_BISON_CXXSTD_testbody(20)],
154 _BISON_CXXSTD_98_snippet
155 _BISON_CXXSTD_03_snippet
156 _BISON_CXXSTD_11_snippet
157 _BISON_CXXSTD_14_snippet
158 _BISON_CXXSTD_17_snippet
159 _BISON_CXXSTD_20_snippet
162 m4_define([_BISON_CXXSTD_testbody(2b)],
164 _BISON_CXXSTD_98_snippet
165 _BISON_CXXSTD_03_snippet
166 _BISON_CXXSTD_11_snippet
167 _BISON_CXXSTD_14_snippet
168 _BISON_CXXSTD_17_snippet
169 _BISON_CXXSTD_20_snippet
170 _BISON_CXXSTD_2B_snippet
174 m4_define([_BISON_CXXSTD_testbody],
176 [m4_indir([$0($1)], m4_shift2($@))],
177 [m4_fatal([$0: unknown C++ standard: $1])])])
182 # Check whether the C++ compiler supports STD (11, 98, 2b, etc.).
183 # If it does, AC_SUBST 'CXX<STD>_CXXFLAGS' to the corresponding flags.
184 AC_DEFUN([BISON_CXXSTD],
185 [AC_REQUIRE([AC_PROG_CXX])
187 for f in '-std=c++$1' '-std=c++$1 -stdlib=libc++'
189 BISON_CHECK_COMPILER_FLAG([$f],
190 [AC_SUBST(m4_toupper([CXX$1_CXXFLAGS]), [$f]) break],
192 [_BISON_CXXSTD_testbody($1)])