aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite
diff options
context:
space:
mode:
authorMartin Liska <mliska@suse.cz>2022-11-08 12:36:43 +0100
committerMartin Liska <mliska@suse.cz>2022-11-08 12:36:43 +0100
commit4b13c73bba935443be3207abf26f7ba05f79badc (patch)
treea6bb1525d07859fa8fc6f61dd13df7ddfd1ac254 /libstdc++-v3/testsuite
parent33f5dde0cd15df9cf89b29280d4ff5fcf7b30e66 (diff)
parentfa271afb58423014e2feef9f15c1a87428e64ddc (diff)
downloadgcc-devel/sphinx.zip
gcc-devel/sphinx.tar.gz
gcc-devel/sphinx.tar.bz2
Merge branch 'master' into devel/sphinxdevel/sphinx
Diffstat (limited to 'libstdc++-v3/testsuite')
-rw-r--r--libstdc++-v3/testsuite/18_support/comparisons/algorithms/fallback.cc6
-rw-r--r--libstdc++-v3/testsuite/20_util/from_chars/pr107468.cc42
-rw-r--r--libstdc++-v3/testsuite/20_util/to_chars/float128_c++23.cc105
-rw-r--r--libstdc++-v3/testsuite/std/ranges/adaptors/as_rvalue/1.cc47
-rw-r--r--libstdc++-v3/testsuite/std/ranges/cartesian_product/1.cc186
5 files changed, 383 insertions, 3 deletions
diff --git a/libstdc++-v3/testsuite/18_support/comparisons/algorithms/fallback.cc b/libstdc++-v3/testsuite/18_support/comparisons/algorithms/fallback.cc
index 05e1bf7..8bf78fa 100644
--- a/libstdc++-v3/testsuite/18_support/comparisons/algorithms/fallback.cc
+++ b/libstdc++-v3/testsuite/18_support/comparisons/algorithms/fallback.cc
@@ -31,12 +31,12 @@ template<typename T, typename U>
using adl::S;
-static_assert( has_strong_order_fallback<S, S> );
+static_assert( ! has_strong_order_fallback<S, S> );
static_assert( has_strong_order_fallback<const S, S> );
static_assert( ! has_strong_order_fallback<const S, const S> );
-static_assert( has_weak_order_fallback<S, S> );
+static_assert( ! has_weak_order_fallback<S, S> );
static_assert( has_weak_order_fallback<const S, S> );
static_assert( ! has_weak_order_fallback<const S, const S> );
-static_assert( has_partial_order_fallback<S, S> );
+static_assert( ! has_partial_order_fallback<S, S> );
static_assert( ! has_partial_order_fallback<const S, S> ); // LWG 3465
static_assert( ! has_partial_order_fallback<const S, const S> );
diff --git a/libstdc++-v3/testsuite/20_util/from_chars/pr107468.cc b/libstdc++-v3/testsuite/20_util/from_chars/pr107468.cc
new file mode 100644
index 0000000..95bf669
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/from_chars/pr107468.cc
@@ -0,0 +1,42 @@
+// Copyright (C) 2022 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
+// <http://www.gnu.org/licenses/>.
+
+// { dg-do run { target c++17 } }
+// { dg-add-options ieee }
+
+#include <charconv>
+#include <string>
+#include <cfenv>
+#include <testsuite_hooks.h>
+
+int
+main()
+{
+ // FP from_char not available otherwise.
+#if __cpp_lib_to_chars >= 201611L \
+ && _GLIBCXX_USE_C99_FENV_TR1 \
+ && defined(FE_DOWNWARD) \
+ && defined(_GLIBCXX_FLOAT_IS_IEEE_BINARY32)
+ // PR libstdc++/107468
+ float f;
+ char buf[] = "3.355447e+07";
+ std::fesetround(FE_DOWNWARD);
+ auto [ptr, ec] = std::from_chars(buf, buf + sizeof(buf) - 1, f, std::chars_format::scientific);
+ VERIFY( ec == std::errc() && ptr == buf + sizeof(buf) - 1 );
+ VERIFY( f == 33554472.0f );
+#endif
+}
diff --git a/libstdc++-v3/testsuite/20_util/to_chars/float128_c++23.cc b/libstdc++-v3/testsuite/20_util/to_chars/float128_c++23.cc
new file mode 100644
index 0000000..28824c9
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/to_chars/float128_c++23.cc
@@ -0,0 +1,105 @@
+// Copyright (C) 2022 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
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++2b" }
+// { dg-do run { target c++23 } }
+// { dg-require-effective-target ieee_floats }
+// { dg-require-effective-target size32plus }
+// { dg-add-options ieee }
+
+#include <charconv>
+#include <stdfloat>
+#include <limits>
+#include <numbers>
+#include <testsuite_hooks.h>
+
+#if defined(__STDCPP_FLOAT128_T__) \
+ && (defined(_GLIBCXX_LDOUBLE_IS_IEEE_BINARY128) \
+ || defined(_GLIBCXX_HAVE_FLOAT128_MATH))
+void
+test(std::chars_format fmt = std::chars_format{})
+{
+ std::float128_t tests[] = {
+ std::numeric_limits<std::float128_t>::denorm_min(),
+ std::numeric_limits<std::float128_t>::min(),
+ 0.0f128,
+ -42.0f128,
+ 1234.5678912345f128,
+ std::numbers::e_v<std::float128_t>,
+ std::numbers::log2e_v<std::float128_t>,
+ std::numbers::log10e_v<std::float128_t>,
+ std::numbers::pi_v<std::float128_t>,
+ std::numbers::inv_pi_v<std::float128_t>,
+ std::numbers::inv_sqrtpi_v<std::float128_t>,
+ std::numbers::ln2_v<std::float128_t>,
+ std::numbers::ln10_v<std::float128_t>,
+ std::numbers::sqrt2_v<std::float128_t>,
+ std::numbers::sqrt3_v<std::float128_t>,
+ std::numbers::inv_sqrt3_v<std::float128_t>,
+ std::numbers::egamma_v<std::float128_t>,
+ std::numbers::phi_v<std::float128_t>,
+ std::numeric_limits<std::float128_t>::max()
+ };
+ char str1[10000], str2[10000];
+ for (auto u : tests)
+ {
+ auto [ptr1, ec1] = std::to_chars(str1, str1 + sizeof(str1), u, fmt);
+ VERIFY( ec1 == std::errc() );
+// std::cout << i << ' ' << std::string_view (str1, ptr1) << '\n';
+ if (fmt == std::chars_format::fixed)
+ {
+ auto [ptr2, ec2] = std::to_chars(str2, str2 + (ptr1 - str1), u, fmt);
+ VERIFY( ec2 == std::errc() && ptr2 - str2 == ptr1 - str1 );
+ auto [ptr3, ec3] = std::to_chars(str2, str2 + (ptr1 - str1 - 1), u, fmt);
+ VERIFY( ec3 != std::errc() );
+ }
+ std::float128_t v;
+ auto [ptr4, ec4] = std::from_chars(str1, ptr1, v,
+ fmt == std::chars_format{}
+ ? std::chars_format::general : fmt);
+ VERIFY( ec4 == std::errc() && ptr4 == ptr1 );
+ VERIFY( u == v );
+
+ auto [ptr5, ec5] = std::to_chars(str1, str1 + sizeof(str1), u, fmt, 90);
+ VERIFY( ec5 == std::errc() );
+// std::cout << i << ' ' << std::string_view (str1, ptr5) << '\n';
+ v = 4.0f128;
+ auto [ptr6, ec6] = std::from_chars(str1, ptr5, v,
+ fmt == std::chars_format{}
+ ? std::chars_format::general : fmt);
+ VERIFY( ec6 == std::errc() && ptr6 == ptr5 );
+ if (fmt == std::chars_format::fixed && u > 0.0f128 && u < 0.000001f128)
+ VERIFY( v == 0.0 );
+ else
+ VERIFY( u == v );
+ }
+}
+#endif
+
+int
+main()
+{
+#if defined(__STDCPP_FLOAT128_T__) \
+ && (defined(_GLIBCXX_LDOUBLE_IS_IEEE_BINARY128) \
+ || defined(_GLIBCXX_HAVE_FLOAT128_MATH))
+ test();
+ test(std::chars_format::fixed);
+ test(std::chars_format::scientific);
+ test(std::chars_format::general);
+ test(std::chars_format::hex);
+#endif
+}
diff --git a/libstdc++-v3/testsuite/std/ranges/adaptors/as_rvalue/1.cc b/libstdc++-v3/testsuite/std/ranges/adaptors/as_rvalue/1.cc
new file mode 100644
index 0000000..8ca4f50
--- /dev/null
+++ b/libstdc++-v3/testsuite/std/ranges/adaptors/as_rvalue/1.cc
@@ -0,0 +1,47 @@
+// { dg-options "-std=gnu++23" }
+// { dg-do run { target c++23 } }
+
+#include <ranges>
+#include <algorithm>
+#include <memory>
+#include <testsuite_hooks.h>
+#include <testsuite_iterators.h>
+
+namespace ranges = std::ranges;
+namespace views = std::views;
+
+constexpr bool
+test01()
+{
+
+ std::unique_ptr<int> a[3] = { std::make_unique<int>(1),
+ std::make_unique<int>(2),
+ std::make_unique<int>(3) };
+ std::unique_ptr<int> b[3];
+ auto v = a | views::as_rvalue;
+ ranges::copy(v, b);
+ VERIFY( ranges::all_of(a, [](auto& p) { return p.get() == nullptr; }) );
+ VERIFY( ranges::equal(b | views::transform([](auto& p) { return *p; }), (int[]){1, 2, 3}) );
+
+ return true;
+}
+
+void
+test02()
+{
+ std::unique_ptr<int> x = std::make_unique<int>(42);
+ std::unique_ptr<int> y;
+ __gnu_test::test_input_range rx(&x, &x+1);
+ auto v = rx | views::as_rvalue;
+ static_assert(!ranges::common_range<decltype(v)>);
+ ranges::copy(v, &y);
+ VERIFY( x.get() == nullptr );
+ VERIFY( *y == 42 );
+}
+
+int
+main()
+{
+ static_assert(test01());
+ test02();
+}
diff --git a/libstdc++-v3/testsuite/std/ranges/cartesian_product/1.cc b/libstdc++-v3/testsuite/std/ranges/cartesian_product/1.cc
new file mode 100644
index 0000000..d6e4b53
--- /dev/null
+++ b/libstdc++-v3/testsuite/std/ranges/cartesian_product/1.cc
@@ -0,0 +1,186 @@
+// { dg-options "-std=gnu++23" }
+// { dg-do run { target c++23 } }
+
+#include <ranges>
+#include <algorithm>
+#include <testsuite_hooks.h>
+#include <testsuite_iterators.h>
+
+namespace ranges = std::ranges;
+namespace views = std::views;
+
+constexpr bool
+test01()
+{
+ int x[] = {1, 2, 3};
+ int y[] = {4, 5, 6};
+ int z[] = {7, 8};
+ int w[] = {9};
+
+ auto v0 = views::cartesian_product();
+ VERIFY( ranges::end(v0) - ranges::begin(v0) == 0 );
+ VERIFY( ranges::size(v0) == 0 );
+ VERIFY( ranges::empty(v0) );
+
+ auto v1 = views::cartesian_product(x);
+ VERIFY( ranges::end(v1) - ranges::begin(v1) == 3 );
+ VERIFY( ranges::size(v1) == 3 );
+ VERIFY( ranges::equal(v1 | views::keys, x) );
+ VERIFY( std::get<0>(v1[0]) == 1 );
+ VERIFY( std::get<0>(v1[1]) == 2 );
+ VERIFY( std::get<0>(v1[2]) == 3 );
+ VERIFY( ranges::equal(v1 | views::reverse | views::keys, x | views::reverse));
+
+ auto v2 = views::cartesian_product(x, y);
+ VERIFY( ranges::size(v2) == 9 );
+ VERIFY( ranges::end(v2) - ranges::begin(v2) == 9 );
+ VERIFY( ranges::equal(v2 | views::keys, (int[]){1, 1, 1, 2, 2, 2, 3, 3, 3}));
+ VERIFY( ranges::equal(v2 | views::values, (int[]){4, 5, 6, 4, 5, 6, 4, 5, 6}));
+ VERIFY( ranges::equal(v2 | views::reverse | views::keys, (int[]){3, 3, 3, 2, 2, 2, 1, 1, 1}) );
+ VERIFY( ranges::equal(v2 | views::reverse | views::values, (int[]){6, 5, 4, 6, 5, 4, 6, 5, 4}) );
+
+ auto v3 = views::cartesian_product(x, y, z);
+ VERIFY( ranges::size(v3) == 18 );
+ VERIFY( ranges::equal(v3, (std::tuple<int,int,int>[]){{1,4,7}, {1,4,8}, {1,5,7}, {1,5,8},
+ {1,6,7}, {1,6,8}, {2,4,7}, {2,4,8},
+ {2,5,7}, {2,5,8}, {2,6,7}, {2,6,8},
+ {3,4,7}, {3,4,8}, {3,5,7}, {3,5,8},
+ {3,6,7}, {3,6,8}}) );
+
+ auto v4 = views::cartesian_product(x, y, z, w);
+ VERIFY( ranges::size(v4) == 18 );
+ VERIFY( ranges::equal(v4 | views::elements<3>, views::repeat(9, 18)) );
+
+ auto i4 = v4.begin(), j4 = i4 + 1;
+ VERIFY( j4 > i4 );
+ VERIFY( i4[0] == std::tuple(1, 4, 7, 9) );
+ VERIFY( i4 + 18 == v4.end() );
+ i4 += 5;
+ VERIFY( i4 != v4.begin() );
+ VERIFY( i4 - 5 == v4.begin() );
+ VERIFY( *i4 == std::tuple(1, 6, 8, 9) );
+ VERIFY( i4 - 5 != i4 );
+ i4 -= 3;
+ VERIFY( *i4 == std::tuple(1, 5, 7, 9) );
+ VERIFY( j4 + 1 == i4 );
+ ranges::iter_swap(i4, j4);
+ VERIFY( *j4 == std::tuple(1, 5, 7, 9) );
+ VERIFY( *i4 == std::tuple(1, 4, 8, 9) );
+
+ return true;
+}
+
+void
+test02()
+{
+ int x[] = {1, 2};
+ __gnu_test::test_input_range<int> rx(x);
+ auto v = views::cartesian_product(rx, x);
+ auto i = v.begin();
+ std::default_sentinel_t s = v.end();
+ VERIFY( i != s );
+ VERIFY( std::get<0>(*i) == 1 && std::get<1>(*i) == 1 );
+ ++i;
+ VERIFY( i != s );
+ VERIFY( std::get<0>(*i) == 1 && std::get<1>(*i) == 2 );
+ ++i;
+ VERIFY( i != s );
+ VERIFY( std::get<0>(*i) == 2 && std::get<1>(*i) == 1 );
+ ++i;
+ VERIFY( i != s );
+ VERIFY( std::get<0>(*i) == 2 && std::get<1>(*i) == 2 );
+ ++i;
+ VERIFY( i == s );
+}
+
+void
+test03()
+{
+ int x[2];
+ __gnu_test::test_input_range<int> rx(x);
+ auto v = views::cartesian_product(views::counted(rx.begin(), 2), x);
+ VERIFY( v.size() == 4 );
+ auto i = v.begin();
+ std::default_sentinel_t s = v.end();
+ VERIFY( i - s == -4 );
+ VERIFY( s - i == 4 );
+ ++i;
+ VERIFY( i - s == -3 );
+ VERIFY( s - i == 3 );
+ ++i;
+ VERIFY( i - s == -2 );
+ VERIFY( s - i == 2 );
+ ++i;
+ VERIFY( i - s == -1 );
+ VERIFY( s - i == 1 );
+ ++i;
+ VERIFY( i - s == 0 );
+ VERIFY( s - i == 0 );
+}
+
+void
+test04()
+{
+ // Exhaustively verify correctness of our iterator addition implementation
+ // (which runs in constant time) for this 24-element cartesian_product_view.
+ int x[4], y[3], z[2], w[1];
+ auto v = views::cartesian_product(x, y, z, w);
+
+ auto n = ranges::ssize(v);
+ for (int i = 0; i <= n; i++)
+ for (int j = 0; i + j <= n; j++)
+ {
+ auto b1 = v.begin();
+ for (int k = 0; k < i + j; k++)
+ ++b1;
+ VERIFY( b1 - v.begin() == i + j );
+ auto b2 = (v.begin() + i) + j;
+ auto b3 = v.begin() + (i + j);
+ VERIFY( b1 == b2 && b2 == b3 );
+
+ auto e1 = v.end();
+ for (int k = 0; k < i + j; k++)
+ --e1;
+ VERIFY( v.end() - e1 == i + j );
+ auto e2 = (v.end() - i) - j;
+ auto e3 = v.end() - (i + j);
+ VERIFY( e1 == e2 && e2 == e3 );
+ }
+}
+
+void
+test05()
+{
+#if __SIZEOF_INT128__
+ auto r = views::iota(__int128(0), __int128(5));
+#else
+ auto r = views::iota(0ll, 5ll);
+#endif
+ auto v = views::cartesian_product(r, r);
+ VERIFY( ranges::size(v) == 25 );
+ VERIFY( v.end() - v.begin() == 25 );
+ VERIFY( v.begin() + ranges::ssize(v) - v.begin() == 25 );
+}
+
+constexpr bool
+test06()
+{
+ int x[] = {1, 2, 3};
+ auto v = views::cartesian_product(x, views::empty<int>, x);
+ VERIFY( ranges::size(v) == 0 );
+ VERIFY( ranges::begin(v) == ranges::end(v) );
+ VERIFY( ranges::begin(v) - ranges::begin(v) == 0 );
+
+ return true;
+}
+
+int
+main()
+{
+ static_assert(test01());
+ test02();
+ test03();
+ test04();
+ test05();
+ static_assert(test06());
+}