From cfc219ae689fd94bbe1bb12686bb04fa09b93046 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Fri, 11 Oct 2019 16:53:52 +0100 Subject: [PATCH] Implement header for C++20 There are currently no tests for [concepts.compare], but they will be added ASAP. * include/Makefile.am: Add new header. * include/Makefile.in: Regenerate. * include/precompiled/stdc++.h: Include . * include/std/concepts: New header for C++20. * include/std/version (__cpp_lib_concepts): Define. * scripts/create_testsuite_files: Look for test files in new std directory. * testsuite/libstdc++-dg/conformance.exp: Likewise. * testsuite/std/concepts/concepts.callable/invocable.cc: New test. * testsuite/std/concepts/concepts.callable/regular_invocable.cc: New test. * testsuite/std/concepts/concepts.callable/relation.cc: New test. * testsuite/std/concepts/concepts.callable/strictweakorder.cc: New test. * testsuite/std/concepts/concepts.lang/concept.arithmetic/ floating_point.cc: New test. * testsuite/std/concepts/concepts.lang/concept.arithmetic/integral.cc: New test. * testsuite/std/concepts/concepts.lang/concept.arithmetic/ signed_integral.cc: New test. * testsuite/std/concepts/concepts.lang/concept.arithmetic/ unsigned_integral.cc: New test. * testsuite/std/concepts/concepts.lang/concept.assignable/1.cc: New test. * testsuite/std/concepts/concepts.lang/concept.common/1.cc: New test. * testsuite/std/concepts/concepts.lang/concept.commonref/1.cc: New test. * testsuite/std/concepts/concepts.lang/concept.constructible/1.cc: New test. * testsuite/std/concepts/concepts.lang/concept.convertible/1.cc: New test. * testsuite/std/concepts/concepts.lang/concept.copyconstructible/1.cc: New test. * testsuite/std/concepts/concepts.lang/concept.defaultconstructible/ 1.cc: New test. * testsuite/std/concepts/concepts.lang/concept.derived/1.cc: New test. * testsuite/std/concepts/concepts.lang/concept.destructible/1.cc: New test. * testsuite/std/concepts/concepts.lang/concept.moveconstructible/1.cc: New test. * testsuite/std/concepts/concepts.lang/concept.same/1.cc: New test. * testsuite/std/concepts/concepts.lang/concept.swappable/swap.cc: New test. * testsuite/std/concepts/concepts.lang/concept.swappable/swappable.cc: New test. * testsuite/std/concepts/concepts.lang/concept.swappable/ swappable_with.cc: New test. * testsuite/std/concepts/concepts.object/copyable.cc: New test. * testsuite/std/concepts/concepts.object/movable.cc: New test. * testsuite/std/concepts/concepts.object/regular.cc: New test. * testsuite/std/concepts/concepts.object/semiregular.cc: New test. From-SVN: r276892 --- libstdc++-v3/ChangeLog | 54 +++ libstdc++-v3/include/Makefile.am | 7 +- libstdc++-v3/include/Makefile.in | 7 +- libstdc++-v3/include/precompiled/stdc++.h | 2 +- libstdc++-v3/include/std/concepts | 351 ++++++++++++++++++ libstdc++-v3/include/std/version | 3 + libstdc++-v3/scripts/create_testsuite_files | 2 +- .../testsuite/libstdc++-dg/conformance.exp | 1 + .../concepts/concepts.callable/invocable.cc | 45 +++ .../concepts.callable/regular_invocable.cc | 45 +++ .../concepts/concepts.callable/relation.cc | 48 +++ .../concepts.callable/strictweakorder.cc | 48 +++ .../concept.arithmetic/floating_point.cc | 58 +++ .../concept.arithmetic/integral.cc | 73 ++++ .../concept.arithmetic/signed_integral.cc | 73 ++++ .../concept.arithmetic/unsigned_integral.cc | 73 ++++ .../concepts.lang/concept.assignable/1.cc | 85 +++++ .../concepts.lang/concept.common/1.cc | 73 ++++ .../concepts.lang/concept.commonref/1.cc | 71 ++++ .../concepts.lang/concept.constructible/1.cc | 89 +++++ .../concepts.lang/concept.convertible/1.cc | 77 ++++ .../concept.copyconstructible/1.cc | 63 ++++ .../concept.defaultconstructible/1.cc | 63 ++++ .../concepts.lang/concept.derived/1.cc | 50 +++ .../concepts.lang/concept.destructible/1.cc | 57 +++ .../concept.moveconstructible/1.cc | 63 ++++ .../concepts/concepts.lang/concept.same/1.cc | 66 ++++ .../concepts.lang/concept.swappable/swap.cc | 78 ++++ .../concept.swappable/swappable.cc | 38 ++ .../concept.swappable/swappable_with.cc | 80 ++++ .../std/concepts/concepts.object/copyable.cc | 108 ++++++ .../std/concepts/concepts.object/movable.cc | 81 ++++ .../std/concepts/concepts.object/regular.cc | 64 ++++ .../concepts/concepts.object/semiregular.cc | 51 +++ 34 files changed, 2139 insertions(+), 8 deletions(-) create mode 100644 libstdc++-v3/include/std/concepts create mode 100644 libstdc++-v3/testsuite/std/concepts/concepts.callable/invocable.cc create mode 100644 libstdc++-v3/testsuite/std/concepts/concepts.callable/regular_invocable.cc create mode 100644 libstdc++-v3/testsuite/std/concepts/concepts.callable/relation.cc create mode 100644 libstdc++-v3/testsuite/std/concepts/concepts.callable/strictweakorder.cc create mode 100644 libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.arithmetic/floating_point.cc create mode 100644 libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.arithmetic/integral.cc create mode 100644 libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.arithmetic/signed_integral.cc create mode 100644 libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.arithmetic/unsigned_integral.cc create mode 100644 libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.assignable/1.cc create mode 100644 libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.common/1.cc create mode 100644 libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.commonref/1.cc create mode 100644 libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.constructible/1.cc create mode 100644 libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.convertible/1.cc create mode 100644 libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.copyconstructible/1.cc create mode 100644 libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.defaultconstructible/1.cc create mode 100644 libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.derived/1.cc create mode 100644 libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.destructible/1.cc create mode 100644 libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.moveconstructible/1.cc create mode 100644 libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.same/1.cc create mode 100644 libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.swappable/swap.cc create mode 100644 libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.swappable/swappable.cc create mode 100644 libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.swappable/swappable_with.cc create mode 100644 libstdc++-v3/testsuite/std/concepts/concepts.object/copyable.cc create mode 100644 libstdc++-v3/testsuite/std/concepts/concepts.object/movable.cc create mode 100644 libstdc++-v3/testsuite/std/concepts/concepts.object/regular.cc create mode 100644 libstdc++-v3/testsuite/std/concepts/concepts.object/semiregular.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 4b1b010ae97..8119455e1ad 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,59 @@ 2019-10-11 Jonathan Wakely + * include/Makefile.am: Add new header. + * include/Makefile.in: Regenerate. + * include/precompiled/stdc++.h: Include . + * include/std/concepts: New header for C++20. + * include/std/version (__cpp_lib_concepts): Define. + * scripts/create_testsuite_files: Look for test files in new std + directory. + * testsuite/libstdc++-dg/conformance.exp: Likewise. + * testsuite/std/concepts/concepts.callable/invocable.cc: New test. + * testsuite/std/concepts/concepts.callable/regular_invocable.cc: New + test. + * testsuite/std/concepts/concepts.callable/relation.cc: New test. + * testsuite/std/concepts/concepts.callable/strictweakorder.cc: New + test. + * testsuite/std/concepts/concepts.lang/concept.arithmetic/ + floating_point.cc: New test. + * testsuite/std/concepts/concepts.lang/concept.arithmetic/integral.cc: + New test. + * testsuite/std/concepts/concepts.lang/concept.arithmetic/ + signed_integral.cc: New test. + * testsuite/std/concepts/concepts.lang/concept.arithmetic/ + unsigned_integral.cc: New test. + * testsuite/std/concepts/concepts.lang/concept.assignable/1.cc: New + test. + * testsuite/std/concepts/concepts.lang/concept.common/1.cc: New test. + * testsuite/std/concepts/concepts.lang/concept.commonref/1.cc: New + test. + * testsuite/std/concepts/concepts.lang/concept.constructible/1.cc: + New test. + * testsuite/std/concepts/concepts.lang/concept.convertible/1.cc: + New test. + * testsuite/std/concepts/concepts.lang/concept.copyconstructible/1.cc: + New test. + * testsuite/std/concepts/concepts.lang/concept.defaultconstructible/ + 1.cc: New test. + * testsuite/std/concepts/concepts.lang/concept.derived/1.cc: + New test. + * testsuite/std/concepts/concepts.lang/concept.destructible/1.cc: + New test. + * testsuite/std/concepts/concepts.lang/concept.moveconstructible/1.cc: + New test. + * testsuite/std/concepts/concepts.lang/concept.same/1.cc: + New test. + * testsuite/std/concepts/concepts.lang/concept.swappable/swap.cc: + New test. + * testsuite/std/concepts/concepts.lang/concept.swappable/swappable.cc: + New test. + * testsuite/std/concepts/concepts.lang/concept.swappable/ + swappable_with.cc: New test. + * testsuite/std/concepts/concepts.object/copyable.cc: New test. + * testsuite/std/concepts/concepts.object/movable.cc: New test. + * testsuite/std/concepts/concepts.object/regular.cc: New test. + * testsuite/std/concepts/concepts.object/semiregular.cc: New test. + * include/std/type_traits (is_same): Replace partial specialization by using __is_same_as built-in in primary template. (is_same_v): Use __is_same_as built-in instead of instantiating the diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am index 3e9540ca047..35ee3cfcd34 100644 --- a/libstdc++-v3/include/Makefile.am +++ b/libstdc++-v3/include/Makefile.am @@ -36,6 +36,7 @@ std_headers = \ ${std_srcdir}/chrono \ ${std_srcdir}/codecvt \ ${std_srcdir}/complex \ + ${std_srcdir}/concepts \ ${std_srcdir}/condition_variable \ ${std_srcdir}/deque \ ${std_srcdir}/execution \ @@ -1379,8 +1380,8 @@ endif # This is a subset of the full install-headers rule. We only need , # , , , , , , , # , , , , , , -# , , , , and any files which they include -# (and which we provide). +# , , , , , +# and any files which they include (and which we provide). # , , , and are installed by # libsupc++, so only the others and the sub-includes are copied here. install-freestanding-headers: @@ -1393,7 +1394,7 @@ install-freestanding-headers: ${glibcxx_srcdir}/$(CPU_DEFINES_SRCDIR)/cpu_defines.h; do \ $(INSTALL_DATA) $${file} $(DESTDIR)${host_installdir}; done $(mkinstalldirs) $(DESTDIR)${gxx_include_dir}/${std_builddir} - for file in limits type_traits atomic bit version; do \ + for file in limits type_traits atomic bit concepts version; do \ $(INSTALL_DATA) ${std_builddir}/$${file} $(DESTDIR)${gxx_include_dir}/${std_builddir}; done $(mkinstalldirs) $(DESTDIR)${gxx_include_dir}/${c_base_builddir} for file in ciso646 cstddef cfloat climits cstdint cstdlib \ diff --git a/libstdc++-v3/include/Makefile.in b/libstdc++-v3/include/Makefile.in index 24e1363951c..5d0488846ff 100644 --- a/libstdc++-v3/include/Makefile.in +++ b/libstdc++-v3/include/Makefile.in @@ -380,6 +380,7 @@ std_headers = \ ${std_srcdir}/chrono \ ${std_srcdir}/codecvt \ ${std_srcdir}/complex \ + ${std_srcdir}/concepts \ ${std_srcdir}/condition_variable \ ${std_srcdir}/deque \ ${std_srcdir}/execution \ @@ -1853,8 +1854,8 @@ ${pch3_output}: ${pch3_source} ${pch2_output} # This is a subset of the full install-headers rule. We only need , # , , , , , , , # , , , , , , -# , , , , and any files which they include -# (and which we provide). +# , , , , , +# and any files which they include (and which we provide). # , , , and are installed by # libsupc++, so only the others and the sub-includes are copied here. install-freestanding-headers: @@ -1867,7 +1868,7 @@ install-freestanding-headers: ${glibcxx_srcdir}/$(CPU_DEFINES_SRCDIR)/cpu_defines.h; do \ $(INSTALL_DATA) $${file} $(DESTDIR)${host_installdir}; done $(mkinstalldirs) $(DESTDIR)${gxx_include_dir}/${std_builddir} - for file in limits type_traits atomic bit version; do \ + for file in limits type_traits atomic bit concepts version; do \ $(INSTALL_DATA) ${std_builddir}/$${file} $(DESTDIR)${gxx_include_dir}/${std_builddir}; done $(mkinstalldirs) $(DESTDIR)${gxx_include_dir}/${c_base_builddir} for file in ciso646 cstddef cfloat climits cstdint cstdlib \ diff --git a/libstdc++-v3/include/precompiled/stdc++.h b/libstdc++-v3/include/precompiled/stdc++.h index 4b668fddc03..fefd6e76845 100644 --- a/libstdc++-v3/include/precompiled/stdc++.h +++ b/libstdc++-v3/include/precompiled/stdc++.h @@ -136,7 +136,7 @@ #if __cplusplus > 201703L #include // #include -// #include +#include #include // #include #include diff --git a/libstdc++-v3/include/std/concepts b/libstdc++-v3/include/std/concepts new file mode 100644 index 00000000000..6b1150a32d2 --- /dev/null +++ b/libstdc++-v3/include/std/concepts @@ -0,0 +1,351 @@ +// -*- C++ -*- + +// Copyright (C) 2019 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received __a copy of the GNU General Public License and +// __a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// . + +/** @file include/concepts + * This is __a Standard C++ Library header. + * @ingroup concepts + */ + +#ifndef _GLIBCXX_CONCEPTS +#define _GLIBCXX_CONCEPTS 1 + +#if __cplusplus > 201703L && __cpp_concepts + +#pragma GCC system_header + +/** + * @defgroup concepts Concepts + * @ingroup utilities + * + * Concepts for checking type requirements. + */ + +#include + +namespace std _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + +#define __cpp_lib_concepts 201806L + + // [concepts.lang], language-related concepts + + namespace __detail + { + template + concept __same_as = __is_same_as(_Tp, _Up); + } // namespace __detail + + /// [concept.same], concept same_as + template + concept same_as + = __detail::__same_as<_Tp, _Up> && __detail::__same_as<_Up, _Tp>; + + /// [concept.derived], concept derived_from + template + concept derived_from = __is_base_of(_Base, _Derived) + && is_convertible_v; + + /// [concept.convertible], concept convertible_to + template + concept convertible_to = is_convertible_v<_From, _To> + && requires(add_rvalue_reference_t<_From> (&__f)()) { + static_cast<_To>(__f()); + }; + + /// [concept.commonref], concept common_reference_with + template + concept common_reference_with + = same_as, common_reference_t<_Up, _Tp>> + && convertible_to<_Tp, common_reference_t<_Tp, _Up>> + && convertible_to<_Up, common_reference_t<_Tp, _Up>>; + + /// [concept.common], concept common_with + template + concept common_with + = same_as, common_type_t<_Up, _Tp>> + && requires { + static_cast>(std::declval<_Tp>()); + static_cast>(std::declval<_Up>()); + } + && common_reference_with, + add_lvalue_reference_t> + && common_reference_with>, + common_reference_t< + add_lvalue_reference_t, + add_lvalue_reference_t>>; + + // [concepts.arithmetic], arithmetic concepts + + template + concept integral = is_integral_v<_Tp>; + + template + concept signed_integral = integral<_Tp> && is_signed_v<_Tp>; + + template + concept unsigned_integral = integral<_Tp> && !signed_integral<_Tp>; + + template + concept floating_point = is_floating_point_v<_Tp>; + + namespace __detail + { + template + using __cref = const remove_reference_t<_Tp>&; + } // namespace __detail + + /// [concept.assignable], concept assignable_from + template + concept assignable_from + = is_lvalue_reference_v<_Lhs> + && common_reference_with<__detail::__cref<_Lhs>, __detail::__cref<_Rhs>> + && requires(_Lhs __lhs, _Rhs&& __rhs) { + { __lhs = static_cast<_Rhs&&>(__rhs) } -> same_as<_Lhs>; + }; + + /// [concept.destructible], concept destructible + template + concept destructible = is_nothrow_destructible_v<_Tp>; + + /// [concept.constructible], concept constructible_from + template + concept constructible_from + = destructible<_Tp> && is_constructible_v<_Tp, _Args...>; + + /// [concept.defaultconstructible], concept default_constructible + template + concept default_constructible = constructible_from<_Tp>; + + /// [concept.moveconstructible], concept move_constructible + template + concept move_constructible + = constructible_from<_Tp, _Tp> && convertible_to<_Tp, _Tp>; + + /// [concept.copyconstructible], concept copy_constructible + template + concept copy_constructible + = move_constructible<_Tp> + && constructible_from<_Tp, _Tp&> && convertible_to<_Tp&, _Tp> + && constructible_from<_Tp, const _Tp&> && convertible_to + && constructible_from<_Tp, const _Tp> && convertible_to; + + // [concept.swappable], concept swappable + + namespace ranges + { + namespace __cust_swap + { + template void swap(_Tp&, _Tp&) = delete; + + template + concept __class_or_enum + = is_class_v<_Tp> || is_union_v<_Tp> || is_enum_v<_Tp>; + + template + concept __adl_swap + = (__class_or_enum> + || __class_or_enum>) + && requires(_Tp&& __t, _Up&& __u) { + swap(static_cast<_Tp&&>(__t), static_cast<_Up&&>(__u)); + }; + + struct _Swap + { + template + requires __adl_swap<_Tp, _Up> + constexpr void operator()(_Tp&& __t, _Up&& __u) const + noexcept(noexcept(swap(std::declval<_Tp>(), std::declval<_Up>()))) + { swap(static_cast<_Tp&&>(__t), static_cast<_Up&&>(__u)); } + + template + requires requires(const _Swap& __swap, _Tp& __e1, _Up& __e2) { + __swap(__e1, __e2); + } + constexpr void + operator()(_Tp (&__e1)[_Num], _Up (&__e2)[_Num]) const + noexcept(noexcept(std::declval()(*__e1, *__e2))) + { + for (size_t __n = 0; __n < _Num; ++__n) + (*this)(__e1[__n], __e2[__n]); + } + + template + requires (!__adl_swap<_Tp&, _Tp&> + && move_constructible<_Tp> && assignable_from<_Tp&, _Tp>) + constexpr void + operator()(_Tp& __e1, _Tp& __e2) const + noexcept(is_nothrow_move_constructible_v<_Tp> + && is_nothrow_move_assignable_v<_Tp>) + { + _Tp __tmp = static_cast<_Tp&&>(__e1); + __e1 = static_cast<_Tp&&>(__e2); + __e2 = static_cast<_Tp&&>(__tmp); + } + }; + } // namespace __cust_swap + + inline namespace __cust + { + inline constexpr __cust_swap::_Swap swap{}; + } // inline namespace __cust + } // namespace ranges + + template + concept swappable + = requires(_Tp& __a, _Tp& __b) { ranges::swap(__a, __b); }; + + template + concept swappable_with = common_reference_with<_Tp, _Up> + && requires(_Tp&& __t, _Up&& __u) { + ranges::swap(static_cast<_Tp&&>(__t), static_cast<_Tp&&>(__t)); + ranges::swap(static_cast<_Up&&>(__u), static_cast<_Up&&>(__u)); + ranges::swap(static_cast<_Tp&&>(__t), static_cast<_Up&&>(__u)); + ranges::swap(static_cast<_Up&&>(__u), static_cast<_Tp&&>(__t)); + }; + + // [concepts.object], Object concepts + + template + concept movable = is_object_v<_Tp> && move_constructible<_Tp> + && assignable_from<_Tp&, _Tp> && swappable<_Tp>; + + template + concept copyable = copy_constructible<_Tp> && movable<_Tp> + && assignable_from<_Tp&, const _Tp&>; + + template + concept semiregular = copyable<_Tp> && default_constructible<_Tp>; + + // [concepts.compare], comparison concepts + + /// [concept.boolean], concept boolean + template + concept boolean + = movable> + && requires(__detail::__cref<_Bp> __b1, __detail::__cref<_Bp> __b2, + const bool __a) { + { __b1 } -> convertible_to; + { !__b1 } -> convertible_to; + { __b1 && __b2 } -> same_as; + { __b1 && __a } -> same_as; + { __a && __b2 } -> same_as; + { __b1 || __b2 } -> same_as; + { __b1 || __a } -> same_as; + { __a || __b2 } -> same_as; + { __b1 == __b2 } -> convertible_to; + { __b1 == __a } -> convertible_to; + { __a == __b2 } -> convertible_to; + { __b1 != __b2 } -> convertible_to; + { __b1 != __a } -> convertible_to; + { __a != __b2 } -> convertible_to; + }; + + // [concept.equalitycomparable], concept equality_comparable + + namespace __detail + { + template + concept __weakly_eq_cmp_with + = requires(__detail::__cref<_Tp> __t, __detail::__cref<_Up> __u) { + { __t == __u } -> boolean; + { __t != __u } -> boolean; + { __u == __t } -> boolean; + { __u != __t } -> boolean; + }; + } // namespace __detail + + template + concept equality_comparable = __detail::__weakly_eq_cmp_with<_Tp, _Tp>; + + template + concept equality_comparable_with + = equality_comparable<_Tp> && equality_comparable<_Up> + && common_reference_with<__detail::__cref<_Tp>, __detail::__cref<_Up>> + && equality_comparable, + __detail::__cref<_Up>>> + && __detail::__weakly_eq_cmp_with<_Tp, _Up>; + + // [concept.totallyordered], concept totally_ordered + template + concept totally_ordered + = equality_comparable<_Tp> + && requires(__detail::__cref<_Tp> __a, __detail::__cref<_Tp> __b) { + { __a < __b } -> boolean; + { __a > __b } -> boolean; + { __a <= __b } -> boolean; + { __a >= __b } -> boolean; + }; + + template + concept totally_ordered_with + = totally_ordered<_Tp> && totally_ordered<_Up> + && common_reference_with<__detail::__cref<_Tp>, __detail::__cref<_Up>> + && totally_ordered, + __detail::__cref<_Up>>> + && equality_comparable_with<_Tp, _Up> + && requires(__detail::__cref<_Tp> __t, __detail::__cref<_Up> __u) { + { __t < __u } -> boolean; + { __t > __u } -> boolean; + { __t <= __u } -> boolean; + { __t >= __u } -> boolean; + { __u < __t } -> boolean; + { __u > __t } -> boolean; + { __u <= __t } -> boolean; + { __u >= __t } -> boolean; + }; + + template + concept regular = semiregular<_Tp> && equality_comparable<_Tp>; + + // [concepts.callable], callable concepts + + // [concept.invocable], concept invocable + template + concept invocable = is_invocable_v<_Fn, _Args...>; + + // [concept.regularinvocable], concept regular_invocable + template + concept regular_invocable = invocable<_Fn, _Args...>; + + // [concept.predicate], concept predicate + template + concept predicate = regular_invocable<_Fn, _Args...> + && boolean>; + + // [concept.relation], concept relation + template + concept relation + = predicate<_Rel, _Tp, _Tp> && predicate<_Rel, _Up, _Up> + && predicate<_Rel, _Tp, _Up> && predicate<_Rel, _Up, _Tp>; + + // [concept.strictweakorder], concept strict_weak_order + template + concept strict_weak_order = relation<_Rel, _Tp, _Up>; + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace +#endif // C++2a + +#endif /* _GLIBCXX_CONCEPTS */ diff --git a/libstdc++-v3/include/std/version b/libstdc++-v3/include/std/version index f758bcd4301..21cc28b3450 100644 --- a/libstdc++-v3/include/std/version +++ b/libstdc++-v3/include/std/version @@ -153,6 +153,9 @@ #define __cpp_lib_atomic_ref 201806L #define __cpp_lib_bind_front 201907L #define __cpp_lib_bounded_array_traits 201902L +#if __cpp_concepts +# define __cpp_lib_concepts 201806L +#endif #define __cpp_lib_constexpr 201711L #define __cpp_lib_constexpr_algorithms 201806L #if __cpp_impl_destroying_delete diff --git a/libstdc++-v3/scripts/create_testsuite_files b/libstdc++-v3/scripts/create_testsuite_files index 40e81cea8a9..52bbb5cda5a 100755 --- a/libstdc++-v3/scripts/create_testsuite_files +++ b/libstdc++-v3/scripts/create_testsuite_files @@ -33,7 +33,7 @@ cd $srcdir # what has to happen when find(1) doesn't support -mindepth, or -xtype. # The directories here should be consistent with libstdc++-dg/conformance.exp dlist=`echo [0-9][0-9]*` -dlist="$dlist abi backward ext performance tr1 tr2 decimal experimental" +dlist="$dlist std abi backward ext performance tr1 tr2 decimal experimental" dlist="$dlist special_functions" find $dlist "(" -type f -o -type l ")" -name "*.cc" -print > $tmp.01 find $dlist "(" -type f -o -type l ")" -name "*.c" -print > $tmp.02 diff --git a/libstdc++-v3/testsuite/libstdc++-dg/conformance.exp b/libstdc++-v3/testsuite/libstdc++-dg/conformance.exp index 6564b046ca8..f334f76a8d9 100644 --- a/libstdc++-v3/testsuite/libstdc++-dg/conformance.exp +++ b/libstdc++-v3/testsuite/libstdc++-dg/conformance.exp @@ -54,6 +54,7 @@ if {[info exists tests_file] && [file exists $tests_file]} { # Find directories that might have tests. # This list should be consistent with scripts/create_testsuite_files set subdirs [glob "$srcdir/\[0-9\]\[0-9\]*"] + lappend subdirs "$srcdir/std" lappend subdirs "$srcdir/abi" lappend subdirs "$srcdir/backward" lappend subdirs "$srcdir/ext" diff --git a/libstdc++-v3/testsuite/std/concepts/concepts.callable/invocable.cc b/libstdc++-v3/testsuite/std/concepts/concepts.callable/invocable.cc new file mode 100644 index 00000000000..d6a8549eaba --- /dev/null +++ b/libstdc++-v3/testsuite/std/concepts/concepts.callable/invocable.cc @@ -0,0 +1,45 @@ +// Copyright (C) 2019 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +#include + +static_assert( ! std::invocable ); +static_assert( std::invocable ); +static_assert( std::invocable ); +static_assert( std::invocable ); +static_assert( ! std::invocable ); +static_assert( ! std::invocable ); + +static_assert( std::invocable ); + +struct A; +static_assert( std::invocable ); +static_assert( ! std::invocable ); +static_assert( std::invocable ); + +struct F +{ + void operator()() const; + void operator()(int); +}; +static_assert( std::invocable ); +static_assert( std::invocable ); +static_assert( std::invocable ); +static_assert( ! std::invocable ); diff --git a/libstdc++-v3/testsuite/std/concepts/concepts.callable/regular_invocable.cc b/libstdc++-v3/testsuite/std/concepts/concepts.callable/regular_invocable.cc new file mode 100644 index 00000000000..f7ca447ab85 --- /dev/null +++ b/libstdc++-v3/testsuite/std/concepts/concepts.callable/regular_invocable.cc @@ -0,0 +1,45 @@ +// Copyright (C) 2019 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +#include + +static_assert( ! std::regular_invocable ); +static_assert( std::regular_invocable ); +static_assert( std::regular_invocable ); +static_assert( std::regular_invocable ); +static_assert( ! std::regular_invocable ); +static_assert( ! std::regular_invocable ); + +static_assert( std::regular_invocable ); + +struct A; +static_assert( std::regular_invocable ); +static_assert( ! std::regular_invocable ); +static_assert( std::regular_invocable ); + +struct F +{ + void operator()() const; + void operator()(int); +}; +static_assert( std::regular_invocable ); +static_assert( std::regular_invocable ); +static_assert( std::regular_invocable ); +static_assert( ! std::regular_invocable ); diff --git a/libstdc++-v3/testsuite/std/concepts/concepts.callable/relation.cc b/libstdc++-v3/testsuite/std/concepts/concepts.callable/relation.cc new file mode 100644 index 00000000000..783c3ab9c4a --- /dev/null +++ b/libstdc++-v3/testsuite/std/concepts/concepts.callable/relation.cc @@ -0,0 +1,48 @@ +// Copyright (C) 2019 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +#include + +static_assert( ! std::relation ); +static_assert( ! std::relation ); +static_assert( ! std::relation ); +static_assert( ! std::relation ); +static_assert( ! std::relation ); +static_assert( ! std::relation ); + +static_assert( std::relation ); +static_assert( std::relation ); + +static_assert( ! std::relation ); + +struct A; +static_assert( ! std::relation ); +static_assert( ! std::relation ); +static_assert( ! std::relation ); +static_assert( std::relation ); + +struct F +{ + void operator()(long, long) const; + bool& operator()(int, const int&) const; +}; +static_assert( ! std::relation ); +static_assert( std::relation ); +static_assert( std::relation ); diff --git a/libstdc++-v3/testsuite/std/concepts/concepts.callable/strictweakorder.cc b/libstdc++-v3/testsuite/std/concepts/concepts.callable/strictweakorder.cc new file mode 100644 index 00000000000..9a01eb259cb --- /dev/null +++ b/libstdc++-v3/testsuite/std/concepts/concepts.callable/strictweakorder.cc @@ -0,0 +1,48 @@ +// Copyright (C) 2019 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +#include + +static_assert( ! std::strict_weak_order ); +static_assert( ! std::strict_weak_order ); +static_assert( ! std::strict_weak_order ); +static_assert( ! std::strict_weak_order ); +static_assert( ! std::strict_weak_order ); +static_assert( ! std::strict_weak_order ); + +static_assert( std::strict_weak_order ); +static_assert( std::strict_weak_order ); + +static_assert( ! std::strict_weak_order ); + +struct A; +static_assert( ! std::strict_weak_order ); +static_assert( ! std::strict_weak_order ); +static_assert( ! std::strict_weak_order ); +static_assert( std::strict_weak_order ); + +struct F +{ + void operator()(long, long) const; + bool& operator()(int, const int&) const; +}; +static_assert( ! std::strict_weak_order ); +static_assert( std::strict_weak_order ); +static_assert( std::strict_weak_order ); diff --git a/libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.arithmetic/floating_point.cc b/libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.arithmetic/floating_point.cc new file mode 100644 index 00000000000..802f2374805 --- /dev/null +++ b/libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.arithmetic/floating_point.cc @@ -0,0 +1,58 @@ +// Copyright (C) 2019 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +#include + +static_assert( std::floating_point ); +static_assert( std::floating_point ); +static_assert( std::floating_point ); +#ifdef _GLIBCXX_USE_FLOAT128 +static_assert( std::floating_point<__float128> ); +#endif + +static_assert( !std::floating_point ); +static_assert( !std::floating_point ); +static_assert( !std::floating_point ); +static_assert( !std::floating_point ); +static_assert( !std::floating_point ); + +#ifdef __GLIBCXX_TYPE_INT_N_0 +static_assert( !std::floating_point ); +#endif + +static_assert( !std::floating_point ); +static_assert( !std::floating_point ); +static_assert( !std::floating_point ); +static_assert( !std::floating_point ); +static_assert( !std::floating_point ); +static_assert( !std::floating_point ); +static_assert( !std::floating_point ); +static_assert( !std::floating_point ); +static_assert( !std::floating_point ); +static_assert( !std::floating_point ); + +enum E { }; +static_assert( !std::floating_point ); +enum class CE { }; +static_assert( !std::floating_point ); +struct A { }; +static_assert( !std::floating_point ); +union B { }; +static_assert( !std::floating_point ); diff --git a/libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.arithmetic/integral.cc b/libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.arithmetic/integral.cc new file mode 100644 index 00000000000..4716dde03b1 --- /dev/null +++ b/libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.arithmetic/integral.cc @@ -0,0 +1,73 @@ +// Copyright (C) 2019 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +#include + +// signed integer types +static_assert( std::integral ); +static_assert( std::integral ); +static_assert( std::integral ); +static_assert( std::integral ); +static_assert( std::integral ); + +// unsigned integer types +static_assert( std::integral ); +static_assert( std::integral ); +static_assert( std::integral ); +static_assert( std::integral ); +static_assert( std::integral ); + +// other integral types +static_assert( std::integral ); +static_assert( std::integral ); +static_assert( std::integral ); +static_assert( std::integral ); +#ifdef _GLIBCXX_USE_WCHAR_T +static_assert( std::integral ); +#endif +#ifdef _GLIBCXX_USE_CHAR8_T +static_assert( std::integral ); +#endif + +#ifdef __GLIBCXX_TYPE_INT_N_0 +static_assert( std::integral ); +static_assert( std::integral ); +#endif + +static_assert( !std::integral ); +static_assert( !std::integral ); +static_assert( !std::integral ); +static_assert( !std::integral ); +static_assert( !std::integral ); +static_assert( !std::integral ); +static_assert( !std::integral ); +static_assert( !std::integral ); +static_assert( !std::integral ); +static_assert( !std::integral ); +static_assert( !std::integral ); + +enum E { }; +static_assert( !std::integral ); +enum class CE { }; +static_assert( !std::integral ); +struct A { }; +static_assert( !std::integral ); +union B { }; +static_assert( !std::integral ); diff --git a/libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.arithmetic/signed_integral.cc b/libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.arithmetic/signed_integral.cc new file mode 100644 index 00000000000..8dd33e51ae7 --- /dev/null +++ b/libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.arithmetic/signed_integral.cc @@ -0,0 +1,73 @@ +// Copyright (C) 2019 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +#include + +// signed integer types +static_assert( std::signed_integral ); +static_assert( std::signed_integral ); +static_assert( std::signed_integral ); +static_assert( std::signed_integral ); +static_assert( std::signed_integral ); + +// unsigned integer types +static_assert( !std::signed_integral ); +static_assert( !std::signed_integral ); +static_assert( !std::signed_integral ); +static_assert( !std::signed_integral ); +static_assert( !std::signed_integral ); + +// other integral types +static_assert( !std::signed_integral ); +static_assert( std::is_signed_v ? std::signed_integral : true ); +static_assert( !std::signed_integral ); +static_assert( !std::signed_integral ); +#ifdef _GLIBCXX_USE_WCHAR_T +static_assert( std::is_signed_v ? std::signed_integral : true ); +#endif +#ifdef _GLIBCXX_USE_CHAR8_T +static_assert( !std::signed_integral ); +#endif + +#ifdef __GLIBCXX_TYPE_INT_N_0 +static_assert( std::signed_integral ); +static_assert( !std::signed_integral ); +#endif + +static_assert( !std::signed_integral ); +static_assert( !std::signed_integral ); +static_assert( !std::signed_integral ); +static_assert( !std::signed_integral ); +static_assert( !std::signed_integral ); +static_assert( !std::signed_integral ); +static_assert( !std::signed_integral ); +static_assert( !std::signed_integral ); +static_assert( !std::signed_integral ); +static_assert( !std::signed_integral ); +static_assert( !std::signed_integral ); + +enum E { }; +static_assert( !std::signed_integral ); +enum class CE { }; +static_assert( !std::signed_integral ); +struct A { }; +static_assert( !std::signed_integral ); +union B { }; +static_assert( !std::signed_integral ); diff --git a/libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.arithmetic/unsigned_integral.cc b/libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.arithmetic/unsigned_integral.cc new file mode 100644 index 00000000000..33affffc895 --- /dev/null +++ b/libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.arithmetic/unsigned_integral.cc @@ -0,0 +1,73 @@ +// Copyright (C) 2019 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +#include + +// unsigned integer types +static_assert( std::unsigned_integral ); +static_assert( std::unsigned_integral ); +static_assert( std::unsigned_integral ); +static_assert( std::unsigned_integral ); +static_assert( std::unsigned_integral ); + +// signed integer types +static_assert( !std::unsigned_integral ); +static_assert( !std::unsigned_integral ); +static_assert( !std::unsigned_integral ); +static_assert( !std::unsigned_integral ); +static_assert( !std::unsigned_integral ); + +// other integral types +static_assert( std::unsigned_integral ); +static_assert( std::is_signed_v ? true : std::unsigned_integral ); +static_assert( std::unsigned_integral ); +static_assert( std::unsigned_integral ); +#ifdef _GLIBCXX_USE_WCHAR_T +static_assert( std::is_signed_v ? true : std::unsigned_integral ); +#endif +#ifdef _GLIBCXX_USE_CHAR8_T +static_assert( std::unsigned_integral ); +#endif + +#ifdef __GLIBCXX_TYPE_INT_N_0 +static_assert( !std::unsigned_integral ); +static_assert( std::unsigned_integral ); +#endif + +static_assert( !std::unsigned_integral ); +static_assert( !std::unsigned_integral ); +static_assert( !std::unsigned_integral ); +static_assert( !std::unsigned_integral ); +static_assert( !std::unsigned_integral ); +static_assert( !std::unsigned_integral ); +static_assert( !std::unsigned_integral ); +static_assert( !std::unsigned_integral ); +static_assert( !std::unsigned_integral ); +static_assert( !std::unsigned_integral ); +static_assert( !std::unsigned_integral ); + +enum E { }; +static_assert( !std::unsigned_integral ); +enum class CE { }; +static_assert( !std::unsigned_integral ); +struct A { }; +static_assert( !std::unsigned_integral ); +union B { }; +static_assert( !std::unsigned_integral ); diff --git a/libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.assignable/1.cc b/libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.assignable/1.cc new file mode 100644 index 00000000000..64773924682 --- /dev/null +++ b/libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.assignable/1.cc @@ -0,0 +1,85 @@ +// Copyright (C) 2019 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +#include + +static_assert( !std::assignable_from ); +static_assert( !std::assignable_from ); +static_assert( std::assignable_from ); +static_assert( !std::assignable_from ); +static_assert( std::assignable_from ); +static_assert( !std::assignable_from ); +static_assert( std::assignable_from ); +static_assert( !std::assignable_from ); +static_assert( std::assignable_from ); +static_assert( std::assignable_from ); +static_assert( std::assignable_from ); +static_assert( std::assignable_from ); +static_assert( !std::assignable_from ); +static_assert( !std::assignable_from ); +static_assert( !std::assignable_from ); +static_assert( !std::assignable_from ); +static_assert( !std::assignable_from ); +static_assert( !std::assignable_from ); +static_assert( !std::assignable_from ); +static_assert( !std::assignable_from ); +static_assert( !std::assignable_from ); +static_assert( !std::assignable_from ); +static_assert( std::assignable_from ); +static_assert( std::assignable_from ); +static_assert( std::assignable_from ); +static_assert( std::assignable_from ); +static_assert( !std::assignable_from ); +static_assert( !std::assignable_from ); + +enum E { }; +static_assert( !std::assignable_from ); +static_assert( std::assignable_from ); +static_assert( std::assignable_from ); +static_assert( std::assignable_from ); +static_assert( !std::assignable_from ); +enum class CE { }; +static_assert( !std::assignable_from ); +static_assert( std::assignable_from ); +static_assert( std::assignable_from ); +static_assert( !std::assignable_from ); +struct A { }; +static_assert( !std::assignable_from ); +static_assert( std::assignable_from ); +static_assert( !std::assignable_from ); +static_assert( std::assignable_from ); +union B { }; +static_assert( !std::assignable_from ); +static_assert( std::assignable_from ); +static_assert( !std::assignable_from ); +static_assert( std::assignable_from ); + +struct C +{ + C(int) { } + C& operator=(const C&) { return *this; } + C& operator=(int) { return *this; } + void operator=(void*) { } +}; +static_assert( std::assignable_from ); +static_assert( std::assignable_from ); +static_assert( std::assignable_from ); +static_assert( !std::assignable_from ); +static_assert( !std::assignable_from ); diff --git a/libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.common/1.cc b/libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.common/1.cc new file mode 100644 index 00000000000..2432ab8e561 --- /dev/null +++ b/libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.common/1.cc @@ -0,0 +1,73 @@ +// Copyright (C) 2019 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +#include + +static_assert( std::common_with ); +static_assert( std::common_with ); +static_assert( std::common_with ); +static_assert( std::common_with ); +static_assert( std::common_with ); +static_assert( ! std::common_with ); +static_assert( ! std::common_with ); +static_assert( ! std::common_with ); + +static_assert( std::common_with ); +static_assert( std::common_with ); +static_assert( std::common_with ); + +struct A { A(int) { } }; +static_assert( std::common_with ); + +struct B { }; +static_assert( ! std::common_with ); + +struct C { C(const A&) { } }; +static_assert( std::common_with ); +static_assert( std::common_with ); +static_assert( std::common_with ); +static_assert( std::common_with ); + +struct D; +struct E { E(const D&) { } }; +struct D { D(const E&) { } }; +static_assert( ! std::common_with ); // ambiguous conversion + +struct F { }; +struct G { }; +struct H { + H(const F&) { } + H(const G&) { } +}; +namespace std +{ + template<> struct common_type { using type = H; }; + template<> struct common_type { using type = H; }; +} + +static_assert( std::common_with ); +static_assert( std::common_with ); +static_assert( std::common_with ); +static_assert( std::common_with ); + +struct Base { }; +struct Derived : Base { }; +static_assert( std::common_with ); +static_assert( std::common_with ); diff --git a/libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.commonref/1.cc b/libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.commonref/1.cc new file mode 100644 index 00000000000..4b56dd71679 --- /dev/null +++ b/libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.commonref/1.cc @@ -0,0 +1,71 @@ +// Copyright (C) 2019 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +#include + +static_assert( std::common_reference_with ); +static_assert( std::common_reference_with ); +static_assert( std::common_reference_with ); +static_assert( std::common_reference_with ); +static_assert( ! std::common_reference_with ); +static_assert( ! std::common_reference_with ); +static_assert( ! std::common_reference_with ); + +struct A { A(int) { } }; +static_assert( std::common_reference_with ); + +struct B { }; +static_assert( ! std::common_reference_with ); + +struct C { C(A&) { } }; +static_assert( std::common_reference_with ); +static_assert( std::common_reference_with ); +static_assert( std::common_reference_with ); +static_assert( std::common_reference_with ); +static_assert( ! std::common_reference_with ); +static_assert( ! std::common_reference_with ); + +struct D; +struct E { E(D&) { } }; +struct D { D(E&) { } }; +static_assert( ! std::common_reference_with ); // ambiguous conversion + +struct F; +struct G { G(const F&) { } }; +struct F { F(const G&) { } }; +namespace std +{ + template class Qual1, template class Qual2> + struct basic_common_reference + { using type = Qual1>; }; + template class Qual1, template class Qual2> + struct basic_common_reference + { using type = Qual1>; }; +} + +static_assert( ! std::common_reference_with ); +static_assert( std::common_reference_with ); +static_assert( std::common_reference_with ); +static_assert( std::common_reference_with ); + +struct Base { }; +struct Derived : Base { }; +static_assert( std::common_reference_with ); +static_assert( std::common_with ); diff --git a/libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.constructible/1.cc b/libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.constructible/1.cc new file mode 100644 index 00000000000..22a52d02360 --- /dev/null +++ b/libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.constructible/1.cc @@ -0,0 +1,89 @@ +// Copyright (C) 2019 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +#include + +static_assert( !std::constructible_from ); +static_assert( !std::constructible_from ); +static_assert( std::constructible_from ); +static_assert( !std::constructible_from ); +static_assert( std::constructible_from ); +static_assert( std::constructible_from ); +static_assert( std::constructible_from ); +static_assert( std::constructible_from ); +static_assert( std::constructible_from ); +static_assert( std::constructible_from ); +static_assert( std::constructible_from ); +static_assert( !std::constructible_from ); +static_assert( std::constructible_from ); +static_assert( !std::constructible_from ); +static_assert( std::constructible_from ); +static_assert( !std::constructible_from ); +static_assert( std::constructible_from ); +static_assert( std::constructible_from ); +static_assert( std::constructible_from ); +static_assert( std::constructible_from ); +static_assert( !std::constructible_from ); +static_assert( !std::constructible_from ); +static_assert( std::constructible_from ); +static_assert( !std::constructible_from ); +static_assert( std::constructible_from ); +static_assert( std::constructible_from ); +static_assert( std::constructible_from ); +static_assert( std::constructible_from ); +static_assert( !std::constructible_from ); +static_assert( std::constructible_from ); + +enum E { }; +static_assert( std::constructible_from ); +static_assert( std::constructible_from ); +enum class CE { }; +static_assert( std::constructible_from ); +static_assert( std::constructible_from ); +struct A { }; +static_assert( std::constructible_from ); +static_assert( std::constructible_from ); +static_assert( std::constructible_from ); +static_assert( std::constructible_from ); +union B { }; +static_assert( std::constructible_from ); +static_assert( std::constructible_from ); +static_assert( std::constructible_from ); +static_assert( std::constructible_from ); + +struct C +{ + C(void* = nullptr) { } + ~C() noexcept(false) { } +}; +static_assert( !std::constructible_from ); +static_assert( !std::constructible_from ); +static_assert( !std::constructible_from ); + +class D +{ +public: + D() { } + D(int) { } +private: + ~D() { } +}; +static_assert( !std::constructible_from ); +static_assert( !std::constructible_from ); diff --git a/libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.convertible/1.cc b/libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.convertible/1.cc new file mode 100644 index 00000000000..295706c0440 --- /dev/null +++ b/libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.convertible/1.cc @@ -0,0 +1,77 @@ +// Copyright (C) 2019 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +#include + +static_assert( std::convertible_to ); +static_assert( std::convertible_to ); +static_assert( !std::convertible_to ); +static_assert( std::convertible_to ); +static_assert( !std::convertible_to ); +static_assert( std::convertible_to ); +static_assert( std::convertible_to ); +static_assert( !std::convertible_to ); +static_assert( std::convertible_to ); +static_assert( std::convertible_to ); + +static_assert( std::convertible_to ); +static_assert( !std::convertible_to ); +static_assert( !std::convertible_to ); +static_assert( std::convertible_to ); +static_assert( std::convertible_to ); +static_assert( !std::convertible_to ); +static_assert( !std::convertible_to ); + +struct A { }; +static_assert( std::convertible_to ); +static_assert( std::convertible_to ); +static_assert( std::convertible_to ); +static_assert( !std::convertible_to ); +static_assert( !std::convertible_to ); +static_assert( std::convertible_to ); + +struct B : A { }; +static_assert( !std::convertible_to ); +static_assert( std::convertible_to ); +static_assert( std::convertible_to ); +static_assert( std::convertible_to ); +static_assert( std::convertible_to ); +static_assert( !std::convertible_to ); +static_assert( !std::convertible_to ); + +struct C : private A { }; +static_assert( !std::convertible_to ); +static_assert( !std::convertible_to ); + +struct D : A { }; +struct E : B, D { }; +static_assert( !std::convertible_to ); +static_assert( !std::convertible_to ); + +struct F +{ + F(A) { } + F(C&&) { } +}; +static_assert( std::convertible_to ); +static_assert( std::convertible_to ); +static_assert( std::convertible_to ); +static_assert( !std::convertible_to ); +static_assert( !std::convertible_to ); diff --git a/libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.copyconstructible/1.cc b/libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.copyconstructible/1.cc new file mode 100644 index 00000000000..0e7843ebb9d --- /dev/null +++ b/libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.copyconstructible/1.cc @@ -0,0 +1,63 @@ +// Copyright (C) 2019 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +#include + +static_assert( !std::copy_constructible ); +static_assert( std::copy_constructible ); +static_assert( std::copy_constructible ); +static_assert( std::copy_constructible ); +static_assert( std::copy_constructible ); +static_assert( std::copy_constructible ); +static_assert( std::copy_constructible ); +static_assert( !std::copy_constructible ); +static_assert( std::copy_constructible ); +static_assert( !std::copy_constructible ); +static_assert( !std::copy_constructible ); +static_assert( !std::copy_constructible ); +static_assert( std::copy_constructible ); +static_assert( std::copy_constructible ); +static_assert( std::copy_constructible ); + +enum E { }; +static_assert( std::copy_constructible ); +enum class CE { }; +static_assert( std::copy_constructible ); +struct A { }; +static_assert( std::copy_constructible ); +union B { }; +static_assert( std::copy_constructible ); + +struct C +{ + C(void* = nullptr) { } + ~C() noexcept(false) { } +}; +static_assert( !std::copy_constructible ); + +class D +{ +public: + D() { } + D(int) { } +private: + ~D() { } +}; +static_assert( !std::copy_constructible ); diff --git a/libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.defaultconstructible/1.cc b/libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.defaultconstructible/1.cc new file mode 100644 index 00000000000..56a4844a957 --- /dev/null +++ b/libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.defaultconstructible/1.cc @@ -0,0 +1,63 @@ +// Copyright (C) 2019 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +#include + +static_assert( !std::default_constructible ); +static_assert( std::default_constructible ); +static_assert( std::default_constructible ); +static_assert( std::default_constructible ); +static_assert( std::default_constructible ); +static_assert( std::default_constructible ); +static_assert( std::default_constructible ); +static_assert( !std::default_constructible ); +static_assert( !std::default_constructible ); +static_assert( !std::default_constructible ); +static_assert( !std::default_constructible ); +static_assert( std::default_constructible ); +static_assert( !std::default_constructible ); +static_assert( std::default_constructible ); +static_assert( !std::default_constructible ); + +enum E { }; +static_assert( std::default_constructible ); +enum class CE { }; +static_assert( std::default_constructible ); +struct A { }; +static_assert( std::default_constructible ); +union B { }; +static_assert( std::constructible_from ); + +struct C +{ + C(void* = nullptr) { } + ~C() noexcept(false) { } +}; +static_assert( !std::default_constructible ); + +class D +{ +public: + D() { } + D(int) { } +private: + ~D() { } +}; +static_assert( !std::default_constructible ); diff --git a/libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.derived/1.cc b/libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.derived/1.cc new file mode 100644 index 00000000000..f376aee7ee4 --- /dev/null +++ b/libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.derived/1.cc @@ -0,0 +1,50 @@ +// Copyright (C) 2019 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +#include + +static_assert( !std::derived_from ); +static_assert( !std::derived_from ); +static_assert( !std::derived_from ); +static_assert( !std::derived_from ); +static_assert( !std::derived_from ); +static_assert( !std::derived_from ); + +struct A { }; +static_assert( std::derived_from ); +static_assert( std::derived_from ); +static_assert( std::derived_from ); +static_assert( std::derived_from ); + +struct B : A { }; +static_assert( !std::derived_from ); +static_assert( std::derived_from ); +static_assert( std::derived_from ); +static_assert( std::derived_from ); +static_assert( std::derived_from ); + +struct C : private A { }; +static_assert( !std::derived_from ); +static_assert( !std::derived_from ); + +struct D : A { }; +struct E : B, D { }; +static_assert( !std::derived_from ); +static_assert( !std::derived_from ); diff --git a/libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.destructible/1.cc b/libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.destructible/1.cc new file mode 100644 index 00000000000..279072aa4c8 --- /dev/null +++ b/libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.destructible/1.cc @@ -0,0 +1,57 @@ +// Copyright (C) 2019 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +#include + +static_assert( !std::destructible ); +static_assert( std::destructible ); +static_assert( std::destructible ); +static_assert( std::destructible ); +static_assert( std::destructible ); +static_assert( std::destructible ); +static_assert( std::destructible ); +static_assert( !std::destructible ); +static_assert( std::destructible ); +static_assert( !std::destructible ); +static_assert( std::destructible ); +static_assert( std::destructible ); + +enum E { }; +static_assert( std::destructible ); +enum class CE { }; +static_assert( std::destructible ); +struct A { }; +static_assert( std::destructible ); +union B { }; +static_assert( std::destructible ); + +struct C +{ + ~C() noexcept(false) { } +}; +static_assert( !std::destructible ); +class D +{ +public: + D() { } +private: + ~D() { } +}; +static_assert( !std::destructible ); diff --git a/libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.moveconstructible/1.cc b/libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.moveconstructible/1.cc new file mode 100644 index 00000000000..9bdf87bcaa2 --- /dev/null +++ b/libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.moveconstructible/1.cc @@ -0,0 +1,63 @@ +// Copyright (C) 2019 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +#include + +static_assert( !std::move_constructible ); +static_assert( std::move_constructible ); +static_assert( std::move_constructible ); +static_assert( std::move_constructible ); +static_assert( std::move_constructible ); +static_assert( std::move_constructible ); +static_assert( std::move_constructible ); +static_assert( std::move_constructible ); +static_assert( std::move_constructible ); +static_assert( !std::move_constructible ); +static_assert( !std::move_constructible ); +static_assert( !std::move_constructible ); +static_assert( std::move_constructible ); +static_assert( std::move_constructible ); +static_assert( std::move_constructible ); + +enum E { }; +static_assert( std::move_constructible ); +enum class CE { }; +static_assert( std::move_constructible ); +struct A { }; +static_assert( std::move_constructible ); +union B { }; +static_assert( std::move_constructible ); + +struct C +{ + C(void* = nullptr) { } + ~C() noexcept(false) { } +}; +static_assert( !std::move_constructible ); + +class D +{ +public: + D() { } + D(int) { } +private: + ~D() { } +}; +static_assert( !std::move_constructible ); diff --git a/libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.same/1.cc b/libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.same/1.cc new file mode 100644 index 00000000000..dfb66f4df9a --- /dev/null +++ b/libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.same/1.cc @@ -0,0 +1,66 @@ +// Copyright (C) 2019 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +#include + +static_assert( std::same_as ); +static_assert( !std::same_as ); +static_assert( !std::same_as ); +static_assert( !std::same_as ); +static_assert( !std::same_as ); +static_assert( std::same_as ); + +struct A { }; +static_assert( std::same_as ); +static_assert( !std::same_as ); +static_assert( std::same_as ); +static_assert( !std::same_as ); + +struct B : A { }; +static_assert( !std::same_as ); + +template + constexpr int + check_subsumption() + { return 0; } + +template + requires std::same_as + constexpr int + check_subsumption() + { return 1; } + +template + requires std::same_as && std::is_const_v + constexpr int + check_subsumption() + { return 2; } + +template + requires std::same_as && std::is_volatile_v + constexpr int + check_subsumption() + { return 3; } + +static_assert( check_subsumption() == 0 ); +static_assert( check_subsumption() == 1 ); +// These will be ambiguous if same_as doesn't subsume same_as: +static_assert( check_subsumption() == 2 ); +static_assert( check_subsumption() == 3 ); diff --git a/libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.swappable/swap.cc b/libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.swappable/swap.cc new file mode 100644 index 00000000000..0b7f28cc6fb --- /dev/null +++ b/libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.swappable/swap.cc @@ -0,0 +1,78 @@ +// Copyright (C) 2019 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +#include + +namespace nu +{ + struct S { bool swapped = false; }; + constexpr void swap(S& l, S& r) { l.swapped = r.swapped = true; } + struct T { int i; }; + + union U { char c; int i; }; + constexpr void swap(U& l, U& r) { l.i = r.i = 99; } +} + +constexpr bool check_struct_with_adl_swap(int i) +{ + nu::S s1, s2; + std::ranges::swap(s1, s2); + return s1.swapped && s2.swapped; +} + +static_assert(check_struct_with_adl_swap(1)); + +constexpr bool check_array_with_adl_swap(int i) +{ + nu::S s1[2], s2[2]; + std::ranges::swap(s1, s2); + return s1[0].swapped && s2[0].swapped && s1[1].swapped && s2[1].swapped; +} + +static_assert(check_array_with_adl_swap(1)); + +constexpr bool check_struct_without_adl_swap(int i) +{ + nu::T t1{i}, t2{2*i}; + std::ranges::swap(t1, t2); + return t1.i == 2*i && t2.i == i; +} + +static_assert(check_struct_without_adl_swap(1)); + +constexpr bool check_array_without_adl_swap(int i) +{ + nu::T t1[2]{i, 2*i}, t2[2]{3*i, 4*i}; + std::ranges::swap(t1, t2); + return t1[0].i == 3*i && t2[0].i == i && t1[1].i == 4*i && t2[1].i == 2*i; +} + +static_assert(check_array_without_adl_swap(1)); + + +constexpr bool check_union_with_adl_swap(int i) +{ + nu::U u1{}, u2{}; + u1.i = u2.i = i; + std::ranges::swap(u1, u2); + return u1.i == 99 && u2.i == 99; +} + +static_assert(check_union_with_adl_swap(1)); diff --git a/libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.swappable/swappable.cc b/libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.swappable/swappable.cc new file mode 100644 index 00000000000..b5a302468db --- /dev/null +++ b/libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.swappable/swappable.cc @@ -0,0 +1,38 @@ +// Copyright (C) 2019 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +#include + +namespace nu +{ + struct S { bool swapped = false; }; + constexpr void swap(S& l, S& r) { } + struct T { int i; }; + + union U { char c; int i; }; + constexpr void swap(U& l, U& r) { } +} + +static_assert( std::swappable ); +static_assert( !std::swappable ); +static_assert( std::swappable ); +static_assert( !std::swappable ); +static_assert( std::swappable ); +static_assert( !std::swappable ); diff --git a/libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.swappable/swappable_with.cc b/libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.swappable/swappable_with.cc new file mode 100644 index 00000000000..7d1147fdf7b --- /dev/null +++ b/libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.swappable/swappable_with.cc @@ -0,0 +1,80 @@ +// Copyright (C) 2019 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +#include + +static_assert( std::swappable_with ); +static_assert( ! std::swappable_with ); +static_assert( ! std::swappable_with ); +static_assert( ! std::swappable_with ); +static_assert( ! std::swappable_with ); +static_assert( ! std::swappable_with ); + +namespace N1 +{ + struct Immovable + { + Immovable() = default; + Immovable(Immovable&&) = delete; + }; +} +static_assert( ! std::swappable_with ); + +namespace N2 +{ + struct Swappable + { + Swappable() = default; + Swappable(Swappable&&) = delete; + friend void swap(Swappable&, Swappable&) { } + }; +} +static_assert( std::swappable_with ); + +namespace N3 +{ + struct A { }; + struct Proxy { + Proxy(A&) { } + friend void swap(Proxy, Proxy) { } + }; +} + +static_assert( std::swappable_with ); +static_assert( std::swappable_with ); +static_assert( std::swappable_with ); +static_assert( std::swappable_with ); + +struct C { C(int&) { } }; +void swap(int&, C&) { } // not symmetrical +static_assert( ! std::swappable_with ); +static_assert( ! std::swappable_with ); + +struct D { D(int&) { } }; +void swap(int&, D&) { } +void swap(D&&, int&) { } // only accepts rvalues +static_assert( ! std::swappable_with ); +static_assert( ! std::swappable_with ); + +struct E { E(int&) { } }; +void swap(int, E&&) { } // only accepts rvalues +void swap(E&, int) { } +static_assert( ! std::swappable_with ); +static_assert( ! std::swappable_with ); diff --git a/libstdc++-v3/testsuite/std/concepts/concepts.object/copyable.cc b/libstdc++-v3/testsuite/std/concepts/concepts.object/copyable.cc new file mode 100644 index 00000000000..abb16895eb6 --- /dev/null +++ b/libstdc++-v3/testsuite/std/concepts/concepts.object/copyable.cc @@ -0,0 +1,108 @@ +// Copyright (C) 2019 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +#include + +static_assert( std::copyable ); +static_assert( std::copyable ); +static_assert( ! std::copyable ); +static_assert( ! std::copyable ); +static_assert( ! std::copyable ); +static_assert( ! std::copyable ); +static_assert( ! std::copyable ); + +struct Trivial { }; +static_assert( std::copyable ); + +struct NotTrivial +{ + NotTrivial(int) { } + NotTrivial(const NotTrivial&) { } + NotTrivial& operator=(const NotTrivial&) { return *this; } + ~NotTrivial() { } +}; +static_assert( std::copyable ); + +namespace N1 +{ + struct Immovable + { + Immovable() = default; + Immovable(Immovable&&) = delete; + }; +} +static_assert( ! std::copyable ); + +struct Movable +{ + Movable() = default; + Movable(Movable&&) = default; + Movable& operator=(Movable&&) = default; +}; +static_assert( ! std::copyable ); + +struct MovableAndCopyAssignable +{ + MovableAndCopyAssignable() = default; + MovableAndCopyAssignable(MovableAndCopyAssignable&&) = default; + MovableAndCopyAssignable& operator=(MovableAndCopyAssignable&&) = default; + MovableAndCopyAssignable& operator=(const MovableAndCopyAssignable&) = default; +}; +static_assert( ! std::copyable ); + +struct MovableAndCopyConstructible +{ + MovableAndCopyConstructible() = default; + MovableAndCopyConstructible(MovableAndCopyConstructible&&) = default; + MovableAndCopyConstructible(const MovableAndCopyConstructible&) = default; + MovableAndCopyConstructible& operator=(MovableAndCopyConstructible&&) = default; +}; +static_assert( ! std::copyable ); + +namespace N2 +{ + struct Swappable + { + Swappable() = default; + Swappable(Swappable&&) = default; + friend void swap(Swappable&, Swappable&) { } + }; +} +static_assert( ! std::copyable ); + +struct NotAssignable +{ + NotAssignable() = default; + NotAssignable(NotAssignable&&) = default; + NotAssignable& operator=(NotAssignable&&) = default; + NotAssignable(const NotAssignable&) = default; + NotAssignable& operator=(const NotAssignable&) = delete; + friend void swap(NotAssignable&, NotAssignable&) { } +}; +static_assert( ! std::copyable ); + +struct NotSwappable +{ + NotSwappable() = default; + NotSwappable(const NotSwappable&) = default; + NotSwappable& operator=(const NotSwappable&) = default; +}; +void swap(NotSwappable&, NotSwappable&) = delete; +static_assert( std::copyable ); // ranges::swap still works! diff --git a/libstdc++-v3/testsuite/std/concepts/concepts.object/movable.cc b/libstdc++-v3/testsuite/std/concepts/concepts.object/movable.cc new file mode 100644 index 00000000000..48fddc1e113 --- /dev/null +++ b/libstdc++-v3/testsuite/std/concepts/concepts.object/movable.cc @@ -0,0 +1,81 @@ +// Copyright (C) 2019 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +#include + +static_assert( std::movable ); +static_assert( std::movable ); +static_assert( ! std::movable ); +static_assert( ! std::movable ); +static_assert( ! std::movable ); +static_assert( ! std::movable ); +static_assert( ! std::movable ); + +struct Trivial { }; +static_assert( std::movable ); + +struct NotTrivial +{ + NotTrivial(int) { } + NotTrivial(NotTrivial&&) { } + NotTrivial& operator=(NotTrivial&&) { return *this; } + ~NotTrivial() { } +}; +static_assert( std::movable ); + +namespace N1 +{ + struct Immovable + { + Immovable() = default; + Immovable(Immovable&&) = delete; + }; +} +static_assert( ! std::movable ); + +namespace N2 +{ + struct Swappable + { + Swappable() = default; + Swappable(Swappable&&) = delete; + Swappable& operator=(Swappable&&) = default; + friend void swap(Swappable&, Swappable&) { } + }; +} +static_assert( ! std::movable ); + +struct NotAssignable +{ + NotAssignable() = default; + NotAssignable(NotAssignable&&) = default; + NotAssignable& operator=(NotAssignable&&) = delete; + friend void swap(NotAssignable&, NotAssignable&) { } +}; +static_assert( ! std::movable ); + +struct NotSwappable +{ + NotSwappable() = default; + NotSwappable(NotSwappable&&) = default; + NotSwappable& operator=(NotSwappable&&) = default; +}; +void swap(NotSwappable&, NotSwappable&) = delete; +static_assert( std::movable ); // ranges::swap still works! diff --git a/libstdc++-v3/testsuite/std/concepts/concepts.object/regular.cc b/libstdc++-v3/testsuite/std/concepts/concepts.object/regular.cc new file mode 100644 index 00000000000..338cf1ba32c --- /dev/null +++ b/libstdc++-v3/testsuite/std/concepts/concepts.object/regular.cc @@ -0,0 +1,64 @@ +// Copyright (C) 2019 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +#include + +static_assert( std::regular ); +static_assert( std::regular ); +static_assert( ! std::regular ); +static_assert( ! std::regular ); +static_assert( ! std::regular ); +static_assert( ! std::regular ); +static_assert( ! std::regular ); + +struct Trivial { }; +static_assert( ! std::regular ); + +struct NotTrivial +{ + NotTrivial() { } + ~NotTrivial() { } +}; +static_assert( ! std::regular ); + +struct NotDefaultConstructible +{ + NotDefaultConstructible(int) { } +}; +static_assert( ! std::regular ); + +struct HasReference +{ + int& ref; +}; +static_assert( ! std::regular ); + +struct HasEq { }; +bool operator==(HasEq, HasEq) { return true; } +#ifdef __cpp_lib_three_way_comparison +static_assert( std::regular ); +#else +static_assert( ! std::regular ); +#endif + +struct HasEqNeq { }; +bool operator==(HasEqNeq, HasEqNeq) { return true; } +bool operator!=(HasEqNeq, HasEqNeq) { return false; } +static_assert( std::regular ); diff --git a/libstdc++-v3/testsuite/std/concepts/concepts.object/semiregular.cc b/libstdc++-v3/testsuite/std/concepts/concepts.object/semiregular.cc new file mode 100644 index 00000000000..1e095d60194 --- /dev/null +++ b/libstdc++-v3/testsuite/std/concepts/concepts.object/semiregular.cc @@ -0,0 +1,51 @@ +// Copyright (C) 2019 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +#include + +static_assert( std::semiregular ); +static_assert( std::semiregular ); +static_assert( ! std::semiregular ); +static_assert( ! std::semiregular ); +static_assert( ! std::semiregular ); +static_assert( ! std::semiregular ); +static_assert( ! std::semiregular ); + +struct Trivial { }; +static_assert( std::semiregular ); + +struct NotTrivial +{ + NotTrivial() { } + ~NotTrivial() { } +}; +static_assert( std::semiregular ); + +struct NotDefaultConstructible +{ + NotDefaultConstructible(int) { } +}; +static_assert( ! std::semiregular ); + +struct HasReference +{ + int& ref; +}; +static_assert( ! std::semiregular ); -- 2.30.2