C++ Library containing a lot of needful things: Stack Trace, Command Line Parser, Resource Handling, Configuration Files, Unix Command Execution, Directories, Regular Expressions, Tokenizer, Function Trace, Standard Extensions.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ax_cxx_compile_stdcxx.m4 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948
  1. # ===========================================================================
  2. # https://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx.html
  3. # ===========================================================================
  4. #
  5. # SYNOPSIS
  6. #
  7. # AX_CXX_COMPILE_STDCXX(VERSION, [ext|noext], [mandatory|optional])
  8. #
  9. # DESCRIPTION
  10. #
  11. # Check for baseline language coverage in the compiler for the specified
  12. # version of the C++ standard. If necessary, add switches to CXX and
  13. # CXXCPP to enable support. VERSION may be '11' (for the C++11 standard)
  14. # or '14' (for the C++14 standard).
  15. #
  16. # The second argument, if specified, indicates whether you insist on an
  17. # extended mode (e.g. -std=gnu++11) or a strict conformance mode (e.g.
  18. # -std=c++11). If neither is specified, you get whatever works, with
  19. # preference for an extended mode.
  20. #
  21. # The third argument, if specified 'mandatory' or if left unspecified,
  22. # indicates that baseline support for the specified C++ standard is
  23. # required and that the macro should error out if no mode with that
  24. # support is found. If specified 'optional', then configuration proceeds
  25. # regardless, after defining HAVE_CXX${VERSION} if and only if a
  26. # supporting mode is found.
  27. #
  28. # LICENSE
  29. #
  30. # Copyright (c) 2008 Benjamin Kosnik <bkoz@redhat.com>
  31. # Copyright (c) 2012 Zack Weinberg <zackw@panix.com>
  32. # Copyright (c) 2013 Roy Stogner <roystgnr@ices.utexas.edu>
  33. # Copyright (c) 2014, 2015 Google Inc.; contributed by Alexey Sokolov <sokolov@google.com>
  34. # Copyright (c) 2015 Paul Norman <penorman@mac.com>
  35. # Copyright (c) 2015 Moritz Klammler <moritz@klammler.eu>
  36. # Copyright (c) 2016, 2018 Krzesimir Nowak <qdlacz@gmail.com>
  37. #
  38. # Copying and distribution of this file, with or without modification, are
  39. # permitted in any medium without royalty provided the copyright notice
  40. # and this notice are preserved. This file is offered as-is, without any
  41. # warranty.
  42. #serial 10
  43. dnl This macro is based on the code from the AX_CXX_COMPILE_STDCXX_11 macro
  44. dnl (serial version number 13).
  45. AC_DEFUN([AX_CXX_COMPILE_STDCXX], [dnl
  46. m4_if([$1], [11], [ax_cxx_compile_alternatives="11 0x"],
  47. [$1], [14], [ax_cxx_compile_alternatives="14 1y"],
  48. [$1], [17], [ax_cxx_compile_alternatives="17 1z"],
  49. [m4_fatal([invalid first argument `$1' to AX_CXX_COMPILE_STDCXX])])dnl
  50. m4_if([$2], [], [],
  51. [$2], [ext], [],
  52. [$2], [noext], [],
  53. [m4_fatal([invalid second argument `$2' to AX_CXX_COMPILE_STDCXX])])dnl
  54. m4_if([$3], [], [ax_cxx_compile_cxx$1_required=true],
  55. [$3], [mandatory], [ax_cxx_compile_cxx$1_required=true],
  56. [$3], [optional], [ax_cxx_compile_cxx$1_required=false],
  57. [m4_fatal([invalid third argument `$3' to AX_CXX_COMPILE_STDCXX])])
  58. AC_LANG_PUSH([C++])dnl
  59. ac_success=no
  60. m4_if([$2], [noext], [], [dnl
  61. if test x$ac_success = xno; then
  62. for alternative in ${ax_cxx_compile_alternatives}; do
  63. switch="-std=gnu++${alternative}"
  64. cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_$switch])
  65. AC_CACHE_CHECK(whether $CXX supports C++$1 features with $switch,
  66. $cachevar,
  67. [ac_save_CXX="$CXX"
  68. CXX="$CXX $switch"
  69. AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_testbody_$1])],
  70. [eval $cachevar=yes],
  71. [eval $cachevar=no])
  72. CXX="$ac_save_CXX"])
  73. if eval test x\$$cachevar = xyes; then
  74. CXX="$CXX $switch"
  75. if test -n "$CXXCPP" ; then
  76. CXXCPP="$CXXCPP $switch"
  77. fi
  78. ac_success=yes
  79. break
  80. fi
  81. done
  82. fi])
  83. m4_if([$2], [ext], [], [dnl
  84. if test x$ac_success = xno; then
  85. dnl HP's aCC needs +std=c++11 according to:
  86. dnl http://h21007.www2.hp.com/portal/download/files/unprot/aCxx/PDF_Release_Notes/769149-001.pdf
  87. dnl Cray's crayCC needs "-h std=c++11"
  88. for alternative in ${ax_cxx_compile_alternatives}; do
  89. for switch in -std=c++${alternative} +std=c++${alternative} "-h std=c++${alternative}"; do
  90. cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_$switch])
  91. AC_CACHE_CHECK(whether $CXX supports C++$1 features with $switch,
  92. $cachevar,
  93. [ac_save_CXX="$CXX"
  94. CXX="$CXX $switch"
  95. AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_testbody_$1])],
  96. [eval $cachevar=yes],
  97. [eval $cachevar=no])
  98. CXX="$ac_save_CXX"])
  99. if eval test x\$$cachevar = xyes; then
  100. CXX="$CXX $switch"
  101. if test -n "$CXXCPP" ; then
  102. CXXCPP="$CXXCPP $switch"
  103. fi
  104. ac_success=yes
  105. break
  106. fi
  107. done
  108. if test x$ac_success = xyes; then
  109. break
  110. fi
  111. done
  112. fi])
  113. AC_LANG_POP([C++])
  114. if test x$ax_cxx_compile_cxx$1_required = xtrue; then
  115. if test x$ac_success = xno; then
  116. AC_MSG_ERROR([*** A compiler with support for C++$1 language features is required.])
  117. fi
  118. fi
  119. if test x$ac_success = xno; then
  120. HAVE_CXX$1=0
  121. AC_MSG_NOTICE([No compiler with C++$1 support was found])
  122. else
  123. HAVE_CXX$1=1
  124. AC_DEFINE(HAVE_CXX$1,1,
  125. [define if the compiler supports basic C++$1 syntax])
  126. fi
  127. AC_SUBST(HAVE_CXX$1)
  128. ])
  129. dnl Test body for checking C++11 support
  130. m4_define([_AX_CXX_COMPILE_STDCXX_testbody_11],
  131. _AX_CXX_COMPILE_STDCXX_testbody_new_in_11
  132. )
  133. dnl Test body for checking C++14 support
  134. m4_define([_AX_CXX_COMPILE_STDCXX_testbody_14],
  135. _AX_CXX_COMPILE_STDCXX_testbody_new_in_11
  136. _AX_CXX_COMPILE_STDCXX_testbody_new_in_14
  137. )
  138. m4_define([_AX_CXX_COMPILE_STDCXX_testbody_17],
  139. _AX_CXX_COMPILE_STDCXX_testbody_new_in_11
  140. _AX_CXX_COMPILE_STDCXX_testbody_new_in_14
  141. _AX_CXX_COMPILE_STDCXX_testbody_new_in_17
  142. )
  143. dnl Tests for new features in C++11
  144. m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_11], [[
  145. // If the compiler admits that it is not ready for C++11, why torture it?
  146. // Hopefully, this will speed up the test.
  147. #ifndef __cplusplus
  148. #error "This is not a C++ compiler"
  149. #elif __cplusplus < 201103L
  150. #error "This is not a C++11 compiler"
  151. #else
  152. namespace cxx11
  153. {
  154. namespace test_static_assert
  155. {
  156. template <typename T>
  157. struct check
  158. {
  159. static_assert(sizeof(int) <= sizeof(T), "not big enough");
  160. };
  161. }
  162. namespace test_final_override
  163. {
  164. struct Base
  165. {
  166. virtual void f() {}
  167. };
  168. struct Derived : public Base
  169. {
  170. virtual void f() override {}
  171. };
  172. }
  173. namespace test_double_right_angle_brackets
  174. {
  175. template < typename T >
  176. struct check {};
  177. typedef check<void> single_type;
  178. typedef check<check<void>> double_type;
  179. typedef check<check<check<void>>> triple_type;
  180. typedef check<check<check<check<void>>>> quadruple_type;
  181. }
  182. namespace test_decltype
  183. {
  184. int
  185. f()
  186. {
  187. int a = 1;
  188. decltype(a) b = 2;
  189. return a + b;
  190. }
  191. }
  192. namespace test_type_deduction
  193. {
  194. template < typename T1, typename T2 >
  195. struct is_same
  196. {
  197. static const bool value = false;
  198. };
  199. template < typename T >
  200. struct is_same<T, T>
  201. {
  202. static const bool value = true;
  203. };
  204. template < typename T1, typename T2 >
  205. auto
  206. add(T1 a1, T2 a2) -> decltype(a1 + a2)
  207. {
  208. return a1 + a2;
  209. }
  210. int
  211. test(const int c, volatile int v)
  212. {
  213. static_assert(is_same<int, decltype(0)>::value == true, "");
  214. static_assert(is_same<int, decltype(c)>::value == false, "");
  215. static_assert(is_same<int, decltype(v)>::value == false, "");
  216. auto ac = c;
  217. auto av = v;
  218. auto sumi = ac + av + 'x';
  219. auto sumf = ac + av + 1.0;
  220. static_assert(is_same<int, decltype(ac)>::value == true, "");
  221. static_assert(is_same<int, decltype(av)>::value == true, "");
  222. static_assert(is_same<int, decltype(sumi)>::value == true, "");
  223. static_assert(is_same<int, decltype(sumf)>::value == false, "");
  224. static_assert(is_same<int, decltype(add(c, v))>::value == true, "");
  225. return (sumf > 0.0) ? sumi : add(c, v);
  226. }
  227. }
  228. namespace test_noexcept
  229. {
  230. int f() { return 0; }
  231. int g() noexcept { return 0; }
  232. static_assert(noexcept(f()) == false, "");
  233. static_assert(noexcept(g()) == true, "");
  234. }
  235. namespace test_constexpr
  236. {
  237. template < typename CharT >
  238. unsigned long constexpr
  239. strlen_c_r(const CharT *const s, const unsigned long acc) noexcept
  240. {
  241. return *s ? strlen_c_r(s + 1, acc + 1) : acc;
  242. }
  243. template < typename CharT >
  244. unsigned long constexpr
  245. strlen_c(const CharT *const s) noexcept
  246. {
  247. return strlen_c_r(s, 0UL);
  248. }
  249. static_assert(strlen_c("") == 0UL, "");
  250. static_assert(strlen_c("1") == 1UL, "");
  251. static_assert(strlen_c("example") == 7UL, "");
  252. static_assert(strlen_c("another\0example") == 7UL, "");
  253. }
  254. namespace test_rvalue_references
  255. {
  256. template < int N >
  257. struct answer
  258. {
  259. static constexpr int value = N;
  260. };
  261. answer<1> f(int&) { return answer<1>(); }
  262. answer<2> f(const int&) { return answer<2>(); }
  263. answer<3> f(int&&) { return answer<3>(); }
  264. void
  265. test()
  266. {
  267. int i = 0;
  268. const int c = 0;
  269. static_assert(decltype(f(i))::value == 1, "");
  270. static_assert(decltype(f(c))::value == 2, "");
  271. static_assert(decltype(f(0))::value == 3, "");
  272. }
  273. }
  274. namespace test_uniform_initialization
  275. {
  276. struct test
  277. {
  278. static const int zero {};
  279. static const int one {1};
  280. };
  281. static_assert(test::zero == 0, "");
  282. static_assert(test::one == 1, "");
  283. }
  284. namespace test_lambdas
  285. {
  286. void
  287. test1()
  288. {
  289. auto lambda1 = [](){};
  290. auto lambda2 = lambda1;
  291. lambda1();
  292. lambda2();
  293. }
  294. int
  295. test2()
  296. {
  297. auto a = [](int i, int j){ return i + j; }(1, 2);
  298. auto b = []() -> int { return '0'; }();
  299. auto c = [=](){ return a + b; }();
  300. auto d = [&](){ return c; }();
  301. auto e = [a, &b](int x) mutable {
  302. const auto identity = [](int y){ return y; };
  303. for (auto i = 0; i < a; ++i)
  304. a += b--;
  305. return x + identity(a + b);
  306. }(0);
  307. return a + b + c + d + e;
  308. }
  309. int
  310. test3()
  311. {
  312. const auto nullary = [](){ return 0; };
  313. const auto unary = [](int x){ return x; };
  314. using nullary_t = decltype(nullary);
  315. using unary_t = decltype(unary);
  316. const auto higher1st = [](nullary_t f){ return f(); };
  317. const auto higher2nd = [unary](nullary_t f1){
  318. return [unary, f1](unary_t f2){ return f2(unary(f1())); };
  319. };
  320. return higher1st(nullary) + higher2nd(nullary)(unary);
  321. }
  322. }
  323. namespace test_variadic_templates
  324. {
  325. template <int...>
  326. struct sum;
  327. template <int N0, int... N1toN>
  328. struct sum<N0, N1toN...>
  329. {
  330. static constexpr auto value = N0 + sum<N1toN...>::value;
  331. };
  332. template <>
  333. struct sum<>
  334. {
  335. static constexpr auto value = 0;
  336. };
  337. static_assert(sum<>::value == 0, "");
  338. static_assert(sum<1>::value == 1, "");
  339. static_assert(sum<23>::value == 23, "");
  340. static_assert(sum<1, 2>::value == 3, "");
  341. static_assert(sum<5, 5, 11>::value == 21, "");
  342. static_assert(sum<2, 3, 5, 7, 11, 13>::value == 41, "");
  343. }
  344. // http://stackoverflow.com/questions/13728184/template-aliases-and-sfinae
  345. // Clang 3.1 fails with headers of libstd++ 4.8.3 when using std::function
  346. // because of this.
  347. namespace test_template_alias_sfinae
  348. {
  349. struct foo {};
  350. template<typename T>
  351. using member = typename T::member_type;
  352. template<typename T>
  353. void func(...) {}
  354. template<typename T>
  355. void func(member<T>*) {}
  356. void test();
  357. void test() { func<foo>(0); }
  358. }
  359. } // namespace cxx11
  360. #endif // __cplusplus >= 201103L
  361. ]])
  362. dnl Tests for new features in C++14
  363. m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_14], [[
  364. // If the compiler admits that it is not ready for C++14, why torture it?
  365. // Hopefully, this will speed up the test.
  366. #ifndef __cplusplus
  367. #error "This is not a C++ compiler"
  368. #elif __cplusplus < 201402L
  369. #error "This is not a C++14 compiler"
  370. #else
  371. namespace cxx14
  372. {
  373. namespace test_polymorphic_lambdas
  374. {
  375. int
  376. test()
  377. {
  378. const auto lambda = [](auto&&... args){
  379. const auto istiny = [](auto x){
  380. return (sizeof(x) == 1UL) ? 1 : 0;
  381. };
  382. const int aretiny[] = { istiny(args)... };
  383. return aretiny[0];
  384. };
  385. return lambda(1, 1L, 1.0f, '1');
  386. }
  387. }
  388. namespace test_binary_literals
  389. {
  390. constexpr auto ivii = 0b0000000000101010;
  391. static_assert(ivii == 42, "wrong value");
  392. }
  393. namespace test_generalized_constexpr
  394. {
  395. template < typename CharT >
  396. constexpr unsigned long
  397. strlen_c(const CharT *const s) noexcept
  398. {
  399. auto length = 0UL;
  400. for (auto p = s; *p; ++p)
  401. ++length;
  402. return length;
  403. }
  404. static_assert(strlen_c("") == 0UL, "");
  405. static_assert(strlen_c("x") == 1UL, "");
  406. static_assert(strlen_c("test") == 4UL, "");
  407. static_assert(strlen_c("another\0test") == 7UL, "");
  408. }
  409. namespace test_lambda_init_capture
  410. {
  411. int
  412. test()
  413. {
  414. auto x = 0;
  415. const auto lambda1 = [a = x](int b){ return a + b; };
  416. const auto lambda2 = [a = lambda1(x)](){ return a; };
  417. return lambda2();
  418. }
  419. }
  420. namespace test_digit_separators
  421. {
  422. constexpr auto ten_million = 100'000'000;
  423. static_assert(ten_million == 100000000, "");
  424. }
  425. namespace test_return_type_deduction
  426. {
  427. auto f(int& x) { return x; }
  428. decltype(auto) g(int& x) { return x; }
  429. template < typename T1, typename T2 >
  430. struct is_same
  431. {
  432. static constexpr auto value = false;
  433. };
  434. template < typename T >
  435. struct is_same<T, T>
  436. {
  437. static constexpr auto value = true;
  438. };
  439. int
  440. test()
  441. {
  442. auto x = 0;
  443. static_assert(is_same<int, decltype(f(x))>::value, "");
  444. static_assert(is_same<int&, decltype(g(x))>::value, "");
  445. return x;
  446. }
  447. }
  448. } // namespace cxx14
  449. #endif // __cplusplus >= 201402L
  450. ]])
  451. dnl Tests for new features in C++17
  452. m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_17], [[
  453. // If the compiler admits that it is not ready for C++17, why torture it?
  454. // Hopefully, this will speed up the test.
  455. #ifndef __cplusplus
  456. #error "This is not a C++ compiler"
  457. #elif __cplusplus < 201703L
  458. #error "This is not a C++17 compiler"
  459. #else
  460. #include <initializer_list>
  461. #include <utility>
  462. #include <type_traits>
  463. namespace cxx17
  464. {
  465. namespace test_constexpr_lambdas
  466. {
  467. constexpr int foo = [](){return 42;}();
  468. }
  469. namespace test::nested_namespace::definitions
  470. {
  471. }
  472. namespace test_fold_expression
  473. {
  474. template<typename... Args>
  475. int multiply(Args... args)
  476. {
  477. return (args * ... * 1);
  478. }
  479. template<typename... Args>
  480. bool all(Args... args)
  481. {
  482. return (args && ...);
  483. }
  484. }
  485. namespace test_extended_static_assert
  486. {
  487. static_assert (true);
  488. }
  489. namespace test_auto_brace_init_list
  490. {
  491. auto foo = {5};
  492. auto bar {5};
  493. static_assert(std::is_same<std::initializer_list<int>, decltype(foo)>::value);
  494. static_assert(std::is_same<int, decltype(bar)>::value);
  495. }
  496. namespace test_typename_in_template_template_parameter
  497. {
  498. template<template<typename> typename X> struct D;
  499. }
  500. namespace test_fallthrough_nodiscard_maybe_unused_attributes
  501. {
  502. int f1()
  503. {
  504. return 42;
  505. }
  506. [[nodiscard]] int f2()
  507. {
  508. [[maybe_unused]] auto unused = f1();
  509. switch (f1())
  510. {
  511. case 17:
  512. f1();
  513. [[fallthrough]];
  514. case 42:
  515. f1();
  516. }
  517. return f1();
  518. }
  519. }
  520. namespace test_extended_aggregate_initialization
  521. {
  522. struct base1
  523. {
  524. int b1, b2 = 42;
  525. };
  526. struct base2
  527. {
  528. base2() {
  529. b3 = 42;
  530. }
  531. int b3;
  532. };
  533. struct derived : base1, base2
  534. {
  535. int d;
  536. };
  537. derived d1 {{1, 2}, {}, 4}; // full initialization
  538. derived d2 {{}, {}, 4}; // value-initialized bases
  539. }
  540. namespace test_general_range_based_for_loop
  541. {
  542. struct iter
  543. {
  544. int i;
  545. int& operator* ()
  546. {
  547. return i;
  548. }
  549. const int& operator* () const
  550. {
  551. return i;
  552. }
  553. iter& operator++()
  554. {
  555. ++i;
  556. return *this;
  557. }
  558. };
  559. struct sentinel
  560. {
  561. int i;
  562. };
  563. bool operator== (const iter& i, const sentinel& s)
  564. {
  565. return i.i == s.i;
  566. }
  567. bool operator!= (const iter& i, const sentinel& s)
  568. {
  569. return !(i == s);
  570. }
  571. struct range
  572. {
  573. iter begin() const
  574. {
  575. return {0};
  576. }
  577. sentinel end() const
  578. {
  579. return {5};
  580. }
  581. };
  582. void f()
  583. {
  584. range r {};
  585. for (auto i : r)
  586. {
  587. [[maybe_unused]] auto v = i;
  588. }
  589. }
  590. }
  591. namespace test_lambda_capture_asterisk_this_by_value
  592. {
  593. struct t
  594. {
  595. int i;
  596. int foo()
  597. {
  598. return [*this]()
  599. {
  600. return i;
  601. }();
  602. }
  603. };
  604. }
  605. namespace test_enum_class_construction
  606. {
  607. enum class byte : unsigned char
  608. {};
  609. byte foo {42};
  610. }
  611. namespace test_constexpr_if
  612. {
  613. template <bool cond>
  614. int f ()
  615. {
  616. if constexpr(cond)
  617. {
  618. return 13;
  619. }
  620. else
  621. {
  622. return 42;
  623. }
  624. }
  625. }
  626. namespace test_selection_statement_with_initializer
  627. {
  628. int f()
  629. {
  630. return 13;
  631. }
  632. int f2()
  633. {
  634. if (auto i = f(); i > 0)
  635. {
  636. return 3;
  637. }
  638. switch (auto i = f(); i + 4)
  639. {
  640. case 17:
  641. return 2;
  642. default:
  643. return 1;
  644. }
  645. }
  646. }
  647. namespace test_template_argument_deduction_for_class_templates
  648. {
  649. template <typename T1, typename T2>
  650. struct pair
  651. {
  652. pair (T1 p1, T2 p2)
  653. : m1 {p1},
  654. m2 {p2}
  655. {}
  656. T1 m1;
  657. T2 m2;
  658. };
  659. void f()
  660. {
  661. [[maybe_unused]] auto p = pair{13, 42u};
  662. }
  663. }
  664. namespace test_non_type_auto_template_parameters
  665. {
  666. template <auto n>
  667. struct B
  668. {};
  669. B<5> b1;
  670. B<'a'> b2;
  671. }
  672. namespace test_structured_bindings
  673. {
  674. int arr[2] = { 1, 2 };
  675. std::pair<int, int> pr = { 1, 2 };
  676. auto f1() -> int(&)[2]
  677. {
  678. return arr;
  679. }
  680. auto f2() -> std::pair<int, int>&
  681. {
  682. return pr;
  683. }
  684. struct S
  685. {
  686. int x1 : 2;
  687. volatile double y1;
  688. };
  689. S f3()
  690. {
  691. return {};
  692. }
  693. auto [ x1, y1 ] = f1();
  694. auto& [ xr1, yr1 ] = f1();
  695. auto [ x2, y2 ] = f2();
  696. auto& [ xr2, yr2 ] = f2();
  697. const auto [ x3, y3 ] = f3();
  698. }
  699. namespace test_exception_spec_type_system
  700. {
  701. struct Good {};
  702. struct Bad {};
  703. void g1() noexcept;
  704. void g2();
  705. template<typename T>
  706. Bad
  707. f(T*, T*);
  708. template<typename T1, typename T2>
  709. Good
  710. f(T1*, T2*);
  711. static_assert (std::is_same_v<Good, decltype(f(g1, g2))>);
  712. }
  713. namespace test_inline_variables
  714. {
  715. template<class T> void f(T)
  716. {}
  717. template<class T> inline T g(T)
  718. {
  719. return T{};
  720. }
  721. template<> inline void f<>(int)
  722. {}
  723. template<> int g<>(int)
  724. {
  725. return 5;
  726. }
  727. }
  728. } // namespace cxx17
  729. #endif // __cplusplus < 201703L
  730. ]])