Build system: implement REUSE with SPDX identifiers
[lttng-ust.git] / m4 / ax_cxx_compile_stdcxx.m4
1 # SPDX-License-Identifier: FSFAP
2 #
3 # ===========================================================================
4 # https://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx.html
5 # ===========================================================================
6 #
7 # SYNOPSIS
8 #
9 # AX_CXX_COMPILE_STDCXX(VERSION, [ext|noext], [mandatory|optional])
10 #
11 # DESCRIPTION
12 #
13 # Check for baseline language coverage in the compiler for the specified
14 # version of the C++ standard. If necessary, add switches to CXX and
15 # CXXCPP to enable support. VERSION may be '11', '14', '17', or '20' for
16 # the respective C++ standard version.
17 #
18 # The second argument, if specified, indicates whether you insist on an
19 # extended mode (e.g. -std=gnu++11) or a strict conformance mode (e.g.
20 # -std=c++11). If neither is specified, you get whatever works, with
21 # preference for no added switch, and then for an extended mode.
22 #
23 # The third argument, if specified 'mandatory' or if left unspecified,
24 # indicates that baseline support for the specified C++ standard is
25 # required and that the macro should error out if no mode with that
26 # support is found. If specified 'optional', then configuration proceeds
27 # regardless, after defining HAVE_CXX${VERSION} if and only if a
28 # supporting mode is found.
29 #
30 # LICENSE
31 #
32 # Copyright (c) 2008 Benjamin Kosnik <bkoz@redhat.com>
33 # Copyright (c) 2012 Zack Weinberg <zackw@panix.com>
34 # Copyright (c) 2013 Roy Stogner <roystgnr@ices.utexas.edu>
35 # Copyright (c) 2014, 2015 Google Inc.; contributed by Alexey Sokolov <sokolov@google.com>
36 # Copyright (c) 2015 Paul Norman <penorman@mac.com>
37 # Copyright (c) 2015 Moritz Klammler <moritz@klammler.eu>
38 # Copyright (c) 2016, 2018 Krzesimir Nowak <qdlacz@gmail.com>
39 # Copyright (c) 2019 Enji Cooper <yaneurabeya@gmail.com>
40 # Copyright (c) 2020 Jason Merrill <jason@redhat.com>
41 # Copyright (c) 2021 Jörn Heusipp <osmanx@problemloesungsmaschine.de>
42 #
43 # Copying and distribution of this file, with or without modification, are
44 # permitted in any medium without royalty provided the copyright notice
45 # and this notice are preserved. This file is offered as-is, without any
46 # warranty.
47
48 #serial 18
49
50 dnl This macro is based on the code from the AX_CXX_COMPILE_STDCXX_11 macro
51 dnl (serial version number 13).
52
53 AC_DEFUN([AX_CXX_COMPILE_STDCXX], [dnl
54 m4_if([$1], [11], [ax_cxx_compile_alternatives="11 0x"],
55 [$1], [14], [ax_cxx_compile_alternatives="14 1y"],
56 [$1], [17], [ax_cxx_compile_alternatives="17 1z"],
57 [$1], [20], [ax_cxx_compile_alternatives="20"],
58 [m4_fatal([invalid first argument `$1' to AX_CXX_COMPILE_STDCXX])])dnl
59 m4_if([$2], [], [],
60 [$2], [ext], [],
61 [$2], [noext], [],
62 [m4_fatal([invalid second argument `$2' to AX_CXX_COMPILE_STDCXX])])dnl
63 m4_if([$3], [], [ax_cxx_compile_cxx$1_required=true],
64 [$3], [mandatory], [ax_cxx_compile_cxx$1_required=true],
65 [$3], [optional], [ax_cxx_compile_cxx$1_required=false],
66 [m4_fatal([invalid third argument `$3' to AX_CXX_COMPILE_STDCXX])])
67 AC_LANG_PUSH([C++])dnl
68 ac_success=no
69
70 m4_if([$2], [], [dnl
71 AC_CACHE_CHECK(whether $CXX supports C++$1 features by default,
72 ax_cv_cxx_compile_cxx$1,
73 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_testbody_$1])],
74 [ax_cv_cxx_compile_cxx$1=yes],
75 [ax_cv_cxx_compile_cxx$1=no])])
76 if test x$ax_cv_cxx_compile_cxx$1 = xyes; then
77 ac_success=yes
78 fi])
79
80 m4_if([$2], [noext], [], [dnl
81 if test x$ac_success = xno; then
82 for alternative in ${ax_cxx_compile_alternatives}; do
83 switch="-std=gnu++${alternative}"
84 cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_$switch])
85 AC_CACHE_CHECK(whether $CXX supports C++$1 features with $switch,
86 $cachevar,
87 [ac_save_CXX="$CXX"
88 CXX="$CXX $switch"
89 AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_testbody_$1])],
90 [eval $cachevar=yes],
91 [eval $cachevar=no])
92 CXX="$ac_save_CXX"])
93 if eval test x\$$cachevar = xyes; then
94 CXX="$CXX $switch"
95 if test -n "$CXXCPP" ; then
96 CXXCPP="$CXXCPP $switch"
97 fi
98 ac_success=yes
99 break
100 fi
101 done
102 fi])
103
104 m4_if([$2], [ext], [], [dnl
105 if test x$ac_success = xno; then
106 dnl HP's aCC needs +std=c++11 according to:
107 dnl http://h21007.www2.hp.com/portal/download/files/unprot/aCxx/PDF_Release_Notes/769149-001.pdf
108 dnl Cray's crayCC needs "-h std=c++11"
109 dnl MSVC needs -std:c++NN for C++17 and later (default is C++14)
110 for alternative in ${ax_cxx_compile_alternatives}; do
111 for switch in -std=c++${alternative} +std=c++${alternative} "-h std=c++${alternative}" MSVC; do
112 if test x"$switch" = xMSVC; then
113 dnl AS_TR_SH maps both `:` and `=` to `_` so -std:c++17 would collide
114 dnl with -std=c++17. We suffix the cache variable name with _MSVC to
115 dnl avoid this.
116 switch=-std:c++${alternative}
117 cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_${switch}_MSVC])
118 else
119 cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_$switch])
120 fi
121 AC_CACHE_CHECK(whether $CXX supports C++$1 features with $switch,
122 $cachevar,
123 [ac_save_CXX="$CXX"
124 CXX="$CXX $switch"
125 AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_testbody_$1])],
126 [eval $cachevar=yes],
127 [eval $cachevar=no])
128 CXX="$ac_save_CXX"])
129 if eval test x\$$cachevar = xyes; then
130 CXX="$CXX $switch"
131 if test -n "$CXXCPP" ; then
132 CXXCPP="$CXXCPP $switch"
133 fi
134 ac_success=yes
135 break
136 fi
137 done
138 if test x$ac_success = xyes; then
139 break
140 fi
141 done
142 fi])
143 AC_LANG_POP([C++])
144 if test x$ax_cxx_compile_cxx$1_required = xtrue; then
145 if test x$ac_success = xno; then
146 AC_MSG_ERROR([*** A compiler with support for C++$1 language features is required.])
147 fi
148 fi
149 if test x$ac_success = xno; then
150 HAVE_CXX$1=0
151 AC_MSG_NOTICE([No compiler with C++$1 support was found])
152 else
153 HAVE_CXX$1=1
154 AC_DEFINE(HAVE_CXX$1,1,
155 [define if the compiler supports basic C++$1 syntax])
156 fi
157 AC_SUBST(HAVE_CXX$1)
158 ])
159
160
161 dnl Test body for checking C++11 support
162
163 m4_define([_AX_CXX_COMPILE_STDCXX_testbody_11],
164 _AX_CXX_COMPILE_STDCXX_testbody_new_in_11
165 )
166
167 dnl Test body for checking C++14 support
168
169 m4_define([_AX_CXX_COMPILE_STDCXX_testbody_14],
170 _AX_CXX_COMPILE_STDCXX_testbody_new_in_11
171 _AX_CXX_COMPILE_STDCXX_testbody_new_in_14
172 )
173
174 dnl Test body for checking C++17 support
175
176 m4_define([_AX_CXX_COMPILE_STDCXX_testbody_17],
177 _AX_CXX_COMPILE_STDCXX_testbody_new_in_11
178 _AX_CXX_COMPILE_STDCXX_testbody_new_in_14
179 _AX_CXX_COMPILE_STDCXX_testbody_new_in_17
180 )
181
182 dnl Test body for checking C++20 support
183
184 m4_define([_AX_CXX_COMPILE_STDCXX_testbody_20],
185 _AX_CXX_COMPILE_STDCXX_testbody_new_in_11
186 _AX_CXX_COMPILE_STDCXX_testbody_new_in_14
187 _AX_CXX_COMPILE_STDCXX_testbody_new_in_17
188 _AX_CXX_COMPILE_STDCXX_testbody_new_in_20
189 )
190
191
192 dnl Tests for new features in C++11
193
194 m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_11], [[
195
196 // If the compiler admits that it is not ready for C++11, why torture it?
197 // Hopefully, this will speed up the test.
198
199 #ifndef __cplusplus
200
201 #error "This is not a C++ compiler"
202
203 // MSVC always sets __cplusplus to 199711L in older versions; newer versions
204 // only set it correctly if /Zc:__cplusplus is specified as well as a
205 // /std:c++NN switch:
206 // https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/
207 #elif __cplusplus < 201103L && !defined _MSC_VER
208
209 #error "This is not a C++11 compiler"
210
211 #else
212
213 namespace cxx11
214 {
215
216 namespace test_static_assert
217 {
218
219 template <typename T>
220 struct check
221 {
222 static_assert(sizeof(int) <= sizeof(T), "not big enough");
223 };
224
225 }
226
227 namespace test_final_override
228 {
229
230 struct Base
231 {
232 virtual ~Base() {}
233 virtual void f() {}
234 };
235
236 struct Derived : public Base
237 {
238 virtual ~Derived() override {}
239 virtual void f() override {}
240 };
241
242 }
243
244 namespace test_double_right_angle_brackets
245 {
246
247 template < typename T >
248 struct check {};
249
250 typedef check<void> single_type;
251 typedef check<check<void>> double_type;
252 typedef check<check<check<void>>> triple_type;
253 typedef check<check<check<check<void>>>> quadruple_type;
254
255 }
256
257 namespace test_decltype
258 {
259
260 int
261 f()
262 {
263 int a = 1;
264 decltype(a) b = 2;
265 return a + b;
266 }
267
268 }
269
270 namespace test_type_deduction
271 {
272
273 template < typename T1, typename T2 >
274 struct is_same
275 {
276 static const bool value = false;
277 };
278
279 template < typename T >
280 struct is_same<T, T>
281 {
282 static const bool value = true;
283 };
284
285 template < typename T1, typename T2 >
286 auto
287 add(T1 a1, T2 a2) -> decltype(a1 + a2)
288 {
289 return a1 + a2;
290 }
291
292 int
293 test(const int c, volatile int v)
294 {
295 static_assert(is_same<int, decltype(0)>::value == true, "");
296 static_assert(is_same<int, decltype(c)>::value == false, "");
297 static_assert(is_same<int, decltype(v)>::value == false, "");
298 auto ac = c;
299 auto av = v;
300 auto sumi = ac + av + 'x';
301 auto sumf = ac + av + 1.0;
302 static_assert(is_same<int, decltype(ac)>::value == true, "");
303 static_assert(is_same<int, decltype(av)>::value == true, "");
304 static_assert(is_same<int, decltype(sumi)>::value == true, "");
305 static_assert(is_same<int, decltype(sumf)>::value == false, "");
306 static_assert(is_same<int, decltype(add(c, v))>::value == true, "");
307 return (sumf > 0.0) ? sumi : add(c, v);
308 }
309
310 }
311
312 namespace test_noexcept
313 {
314
315 int f() { return 0; }
316 int g() noexcept { return 0; }
317
318 static_assert(noexcept(f()) == false, "");
319 static_assert(noexcept(g()) == true, "");
320
321 }
322
323 namespace test_constexpr
324 {
325
326 template < typename CharT >
327 unsigned long constexpr
328 strlen_c_r(const CharT *const s, const unsigned long acc) noexcept
329 {
330 return *s ? strlen_c_r(s + 1, acc + 1) : acc;
331 }
332
333 template < typename CharT >
334 unsigned long constexpr
335 strlen_c(const CharT *const s) noexcept
336 {
337 return strlen_c_r(s, 0UL);
338 }
339
340 static_assert(strlen_c("") == 0UL, "");
341 static_assert(strlen_c("1") == 1UL, "");
342 static_assert(strlen_c("example") == 7UL, "");
343 static_assert(strlen_c("another\0example") == 7UL, "");
344
345 }
346
347 namespace test_rvalue_references
348 {
349
350 template < int N >
351 struct answer
352 {
353 static constexpr int value = N;
354 };
355
356 answer<1> f(int&) { return answer<1>(); }
357 answer<2> f(const int&) { return answer<2>(); }
358 answer<3> f(int&&) { return answer<3>(); }
359
360 void
361 test()
362 {
363 int i = 0;
364 const int c = 0;
365 static_assert(decltype(f(i))::value == 1, "");
366 static_assert(decltype(f(c))::value == 2, "");
367 static_assert(decltype(f(0))::value == 3, "");
368 }
369
370 }
371
372 namespace test_uniform_initialization
373 {
374
375 struct test
376 {
377 static const int zero {};
378 static const int one {1};
379 };
380
381 static_assert(test::zero == 0, "");
382 static_assert(test::one == 1, "");
383
384 }
385
386 namespace test_lambdas
387 {
388
389 void
390 test1()
391 {
392 auto lambda1 = [](){};
393 auto lambda2 = lambda1;
394 lambda1();
395 lambda2();
396 }
397
398 int
399 test2()
400 {
401 auto a = [](int i, int j){ return i + j; }(1, 2);
402 auto b = []() -> int { return '0'; }();
403 auto c = [=](){ return a + b; }();
404 auto d = [&](){ return c; }();
405 auto e = [a, &b](int x) mutable {
406 const auto identity = [](int y){ return y; };
407 for (auto i = 0; i < a; ++i)
408 a += b--;
409 return x + identity(a + b);
410 }(0);
411 return a + b + c + d + e;
412 }
413
414 int
415 test3()
416 {
417 const auto nullary = [](){ return 0; };
418 const auto unary = [](int x){ return x; };
419 using nullary_t = decltype(nullary);
420 using unary_t = decltype(unary);
421 const auto higher1st = [](nullary_t f){ return f(); };
422 const auto higher2nd = [unary](nullary_t f1){
423 return [unary, f1](unary_t f2){ return f2(unary(f1())); };
424 };
425 return higher1st(nullary) + higher2nd(nullary)(unary);
426 }
427
428 }
429
430 namespace test_variadic_templates
431 {
432
433 template <int...>
434 struct sum;
435
436 template <int N0, int... N1toN>
437 struct sum<N0, N1toN...>
438 {
439 static constexpr auto value = N0 + sum<N1toN...>::value;
440 };
441
442 template <>
443 struct sum<>
444 {
445 static constexpr auto value = 0;
446 };
447
448 static_assert(sum<>::value == 0, "");
449 static_assert(sum<1>::value == 1, "");
450 static_assert(sum<23>::value == 23, "");
451 static_assert(sum<1, 2>::value == 3, "");
452 static_assert(sum<5, 5, 11>::value == 21, "");
453 static_assert(sum<2, 3, 5, 7, 11, 13>::value == 41, "");
454
455 }
456
457 // http://stackoverflow.com/questions/13728184/template-aliases-and-sfinae
458 // Clang 3.1 fails with headers of libstd++ 4.8.3 when using std::function
459 // because of this.
460 namespace test_template_alias_sfinae
461 {
462
463 struct foo {};
464
465 template<typename T>
466 using member = typename T::member_type;
467
468 template<typename T>
469 void func(...) {}
470
471 template<typename T>
472 void func(member<T>*) {}
473
474 void test();
475
476 void test() { func<foo>(0); }
477
478 }
479
480 } // namespace cxx11
481
482 #endif // __cplusplus >= 201103L
483
484 ]])
485
486
487 dnl Tests for new features in C++14
488
489 m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_14], [[
490
491 // If the compiler admits that it is not ready for C++14, why torture it?
492 // Hopefully, this will speed up the test.
493
494 #ifndef __cplusplus
495
496 #error "This is not a C++ compiler"
497
498 #elif __cplusplus < 201402L && !defined _MSC_VER
499
500 #error "This is not a C++14 compiler"
501
502 #else
503
504 namespace cxx14
505 {
506
507 namespace test_polymorphic_lambdas
508 {
509
510 int
511 test()
512 {
513 const auto lambda = [](auto&&... args){
514 const auto istiny = [](auto x){
515 return (sizeof(x) == 1UL) ? 1 : 0;
516 };
517 const int aretiny[] = { istiny(args)... };
518 return aretiny[0];
519 };
520 return lambda(1, 1L, 1.0f, '1');
521 }
522
523 }
524
525 namespace test_binary_literals
526 {
527
528 constexpr auto ivii = 0b0000000000101010;
529 static_assert(ivii == 42, "wrong value");
530
531 }
532
533 namespace test_generalized_constexpr
534 {
535
536 template < typename CharT >
537 constexpr unsigned long
538 strlen_c(const CharT *const s) noexcept
539 {
540 auto length = 0UL;
541 for (auto p = s; *p; ++p)
542 ++length;
543 return length;
544 }
545
546 static_assert(strlen_c("") == 0UL, "");
547 static_assert(strlen_c("x") == 1UL, "");
548 static_assert(strlen_c("test") == 4UL, "");
549 static_assert(strlen_c("another\0test") == 7UL, "");
550
551 }
552
553 namespace test_lambda_init_capture
554 {
555
556 int
557 test()
558 {
559 auto x = 0;
560 const auto lambda1 = [a = x](int b){ return a + b; };
561 const auto lambda2 = [a = lambda1(x)](){ return a; };
562 return lambda2();
563 }
564
565 }
566
567 namespace test_digit_separators
568 {
569
570 constexpr auto ten_million = 100'000'000;
571 static_assert(ten_million == 100000000, "");
572
573 }
574
575 namespace test_return_type_deduction
576 {
577
578 auto f(int& x) { return x; }
579 decltype(auto) g(int& x) { return x; }
580
581 template < typename T1, typename T2 >
582 struct is_same
583 {
584 static constexpr auto value = false;
585 };
586
587 template < typename T >
588 struct is_same<T, T>
589 {
590 static constexpr auto value = true;
591 };
592
593 int
594 test()
595 {
596 auto x = 0;
597 static_assert(is_same<int, decltype(f(x))>::value, "");
598 static_assert(is_same<int&, decltype(g(x))>::value, "");
599 return x;
600 }
601
602 }
603
604 } // namespace cxx14
605
606 #endif // __cplusplus >= 201402L
607
608 ]])
609
610
611 dnl Tests for new features in C++17
612
613 m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_17], [[
614
615 // If the compiler admits that it is not ready for C++17, why torture it?
616 // Hopefully, this will speed up the test.
617
618 #ifndef __cplusplus
619
620 #error "This is not a C++ compiler"
621
622 #elif __cplusplus < 201703L && !defined _MSC_VER
623
624 #error "This is not a C++17 compiler"
625
626 #else
627
628 #include <initializer_list>
629 #include <utility>
630 #include <type_traits>
631
632 namespace cxx17
633 {
634
635 namespace test_constexpr_lambdas
636 {
637
638 constexpr int foo = [](){return 42;}();
639
640 }
641
642 namespace test::nested_namespace::definitions
643 {
644
645 }
646
647 namespace test_fold_expression
648 {
649
650 template<typename... Args>
651 int multiply(Args... args)
652 {
653 return (args * ... * 1);
654 }
655
656 template<typename... Args>
657 bool all(Args... args)
658 {
659 return (args && ...);
660 }
661
662 }
663
664 namespace test_extended_static_assert
665 {
666
667 static_assert (true);
668
669 }
670
671 namespace test_auto_brace_init_list
672 {
673
674 auto foo = {5};
675 auto bar {5};
676
677 static_assert(std::is_same<std::initializer_list<int>, decltype(foo)>::value);
678 static_assert(std::is_same<int, decltype(bar)>::value);
679 }
680
681 namespace test_typename_in_template_template_parameter
682 {
683
684 template<template<typename> typename X> struct D;
685
686 }
687
688 namespace test_fallthrough_nodiscard_maybe_unused_attributes
689 {
690
691 int f1()
692 {
693 return 42;
694 }
695
696 [[nodiscard]] int f2()
697 {
698 [[maybe_unused]] auto unused = f1();
699
700 switch (f1())
701 {
702 case 17:
703 f1();
704 [[fallthrough]];
705 case 42:
706 f1();
707 }
708 return f1();
709 }
710
711 }
712
713 namespace test_extended_aggregate_initialization
714 {
715
716 struct base1
717 {
718 int b1, b2 = 42;
719 };
720
721 struct base2
722 {
723 base2() {
724 b3 = 42;
725 }
726 int b3;
727 };
728
729 struct derived : base1, base2
730 {
731 int d;
732 };
733
734 derived d1 {{1, 2}, {}, 4}; // full initialization
735 derived d2 {{}, {}, 4}; // value-initialized bases
736
737 }
738
739 namespace test_general_range_based_for_loop
740 {
741
742 struct iter
743 {
744 int i;
745
746 int& operator* ()
747 {
748 return i;
749 }
750
751 const int& operator* () const
752 {
753 return i;
754 }
755
756 iter& operator++()
757 {
758 ++i;
759 return *this;
760 }
761 };
762
763 struct sentinel
764 {
765 int i;
766 };
767
768 bool operator== (const iter& i, const sentinel& s)
769 {
770 return i.i == s.i;
771 }
772
773 bool operator!= (const iter& i, const sentinel& s)
774 {
775 return !(i == s);
776 }
777
778 struct range
779 {
780 iter begin() const
781 {
782 return {0};
783 }
784
785 sentinel end() const
786 {
787 return {5};
788 }
789 };
790
791 void f()
792 {
793 range r {};
794
795 for (auto i : r)
796 {
797 [[maybe_unused]] auto v = i;
798 }
799 }
800
801 }
802
803 namespace test_lambda_capture_asterisk_this_by_value
804 {
805
806 struct t
807 {
808 int i;
809 int foo()
810 {
811 return [*this]()
812 {
813 return i;
814 }();
815 }
816 };
817
818 }
819
820 namespace test_enum_class_construction
821 {
822
823 enum class byte : unsigned char
824 {};
825
826 byte foo {42};
827
828 }
829
830 namespace test_constexpr_if
831 {
832
833 template <bool cond>
834 int f ()
835 {
836 if constexpr(cond)
837 {
838 return 13;
839 }
840 else
841 {
842 return 42;
843 }
844 }
845
846 }
847
848 namespace test_selection_statement_with_initializer
849 {
850
851 int f()
852 {
853 return 13;
854 }
855
856 int f2()
857 {
858 if (auto i = f(); i > 0)
859 {
860 return 3;
861 }
862
863 switch (auto i = f(); i + 4)
864 {
865 case 17:
866 return 2;
867
868 default:
869 return 1;
870 }
871 }
872
873 }
874
875 namespace test_template_argument_deduction_for_class_templates
876 {
877
878 template <typename T1, typename T2>
879 struct pair
880 {
881 pair (T1 p1, T2 p2)
882 : m1 {p1},
883 m2 {p2}
884 {}
885
886 T1 m1;
887 T2 m2;
888 };
889
890 void f()
891 {
892 [[maybe_unused]] auto p = pair{13, 42u};
893 }
894
895 }
896
897 namespace test_non_type_auto_template_parameters
898 {
899
900 template <auto n>
901 struct B
902 {};
903
904 B<5> b1;
905 B<'a'> b2;
906
907 }
908
909 namespace test_structured_bindings
910 {
911
912 int arr[2] = { 1, 2 };
913 std::pair<int, int> pr = { 1, 2 };
914
915 auto f1() -> int(&)[2]
916 {
917 return arr;
918 }
919
920 auto f2() -> std::pair<int, int>&
921 {
922 return pr;
923 }
924
925 struct S
926 {
927 int x1 : 2;
928 volatile double y1;
929 };
930
931 S f3()
932 {
933 return {};
934 }
935
936 auto [ x1, y1 ] = f1();
937 auto& [ xr1, yr1 ] = f1();
938 auto [ x2, y2 ] = f2();
939 auto& [ xr2, yr2 ] = f2();
940 const auto [ x3, y3 ] = f3();
941
942 }
943
944 namespace test_exception_spec_type_system
945 {
946
947 struct Good {};
948 struct Bad {};
949
950 void g1() noexcept;
951 void g2();
952
953 template<typename T>
954 Bad
955 f(T*, T*);
956
957 template<typename T1, typename T2>
958 Good
959 f(T1*, T2*);
960
961 static_assert (std::is_same_v<Good, decltype(f(g1, g2))>);
962
963 }
964
965 namespace test_inline_variables
966 {
967
968 template<class T> void f(T)
969 {}
970
971 template<class T> inline T g(T)
972 {
973 return T{};
974 }
975
976 template<> inline void f<>(int)
977 {}
978
979 template<> int g<>(int)
980 {
981 return 5;
982 }
983
984 }
985
986 } // namespace cxx17
987
988 #endif // __cplusplus < 201703L && !defined _MSC_VER
989
990 ]])
991
992
993 dnl Tests for new features in C++20
994
995 m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_20], [[
996
997 #ifndef __cplusplus
998
999 #error "This is not a C++ compiler"
1000
1001 #elif __cplusplus < 202002L && !defined _MSC_VER
1002
1003 #error "This is not a C++20 compiler"
1004
1005 #else
1006
1007 #include <version>
1008
1009 namespace cxx20
1010 {
1011
1012 // As C++20 supports feature test macros in the standard, there is no
1013 // immediate need to actually test for feature availability on the
1014 // Autoconf side.
1015
1016 } // namespace cxx20
1017
1018 #endif // __cplusplus < 202002L && !defined _MSC_VER
1019
1020 ]])
This page took 0.051989 seconds and 5 git commands to generate.