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