[gcc/devel/omp/gcc-9] Test for C++20 p0858 - ConstexprIterator requirements.
Tobias Burnus
burnus@gcc.gnu.org
Thu Mar 5 13:57:00 GMT 2020
https://gcc.gnu.org/g:2f5b1cf10ac3b77f41ac2b179bb5f2d2385ff1bb
commit 2f5b1cf10ac3b77f41ac2b179bb5f2d2385ff1bb
Author: Edward Smith-Rowland <emsr@gcc.gnu.org>
Date: Sun Jun 9 21:43:55 2019 +0000
Test for C++20 p0858 - ConstexprIterator requirements.
2019-06-09 Edward Smith-Rowland <3dw4rd@verizon.net>
Test for C++20 p0858 - ConstexprIterator requirements.
* testsuite/21_strings/basic_string_view/requirements/constexpr_iter.cc:
New test.
* testsuite/23_containers/array/requirements/constexpr_iter.cc:
New test.
From-SVN: r272097
Diff:
---
.../requirements/constexpr_iter.cc | 39 ++++++++++++++++++++++
.../array/requirements/constexpr_iter.cc | 38 +++++++++++++++++++++
2 files changed, 77 insertions(+)
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string_view/requirements/constexpr_iter.cc b/libstdc++-v3/testsuite/21_strings/basic_string_view/requirements/constexpr_iter.cc
new file mode 100644
index 0000000..9b179e2
--- /dev/null
+++ b/libstdc++-v3/testsuite/21_strings/basic_string_view/requirements/constexpr_iter.cc
@@ -0,0 +1,39 @@
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+//
+// 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
+// <http://www.gnu.org/licenses/>.
+
+#include <string_view>
+#include <array>
+
+constexpr char
+test()
+{
+ constexpr std::string_view hw("Hello, World!");
+ static_assert('H' == *hw.begin());
+ auto ch = hw[4];
+ static_assert('W' == *(hw.cbegin() + 7));
+
+ return *(hw.cbegin() + 3);
+}
+
+void
+run_test()
+{
+ constexpr char ch = test();
+}
diff --git a/libstdc++-v3/testsuite/23_containers/array/requirements/constexpr_iter.cc b/libstdc++-v3/testsuite/23_containers/array/requirements/constexpr_iter.cc
new file mode 100644
index 0000000..559153f
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/array/requirements/constexpr_iter.cc
@@ -0,0 +1,38 @@
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+//
+// 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
+// <http://www.gnu.org/licenses/>.
+
+#include <array>
+
+constexpr int
+test()
+{
+ constexpr std::array<int, 3> a1{{1, 2, 3}};
+ static_assert(1 == *a1.begin());
+ auto n = a1[0] * a1[1]* a1[2];
+ static_assert(1 == *a1.cbegin());
+
+ return n;
+}
+
+void
+run_test()
+{
+ constexpr int n = test();
+}
More information about the Libstdc++-cvs
mailing list