On 6/8/19 4:28 PM, Jonathan Wakely wrote:
On 08/06/19 12:05 -0400, Ed Smith-Rowland wrote:
On 6/7/19 11:42 AM, Jonathan Wakely wrote:
On 01/06/19 15:40 -0400, Ed Smith-Rowland via libstdc++ wrote:
On 6/1/19 2:42 PM, Ville Voutilainen wrote:
On Sat, 1 Jun 2019 at 21:09, Ed Smith-Rowland <3dw...@verizon.net>
wrote:
On 5/31/19 6:29 PM, Ville Voutilainen wrote:
On Sat, 1 Jun 2019 at 01:24, Ed Smith-Rowland via libstdc++
<libstd...@gcc.gnu.org> wrote:
Greetings,
Iterators for <array> and <string_view> are usabe in a
constexpr context
since C++2017.
This just adds a compile test to make sure and check a box for
C++20
p0858 - ConstexprIterator requirements.
Those tests don't use the iterators in a constexpr context. To do
that, maybe do those std::copy operations
in a constexpr function and then initialize a constexpr variable
with
the result of a call to that function?
Thanks Ville,
I had completely forgotten to make these test functions constexpr
- FIXED.
.but that doesn't enforce a constexpr context. If you add another
function that calls these functions
and initializes a constexpr variable, then we have the enforcement I
seek. Such as
void test2()
{
?????? constexpr char x = test();
}
Ok, third time's a charm.
I was brain dead about the constexpr patch.?? I'm now setting a
constexpr variable from test() in a caller.
But static_assert is a constexpr context no?
Ed
2019-06-03?? Edward Smith-Rowland <3dw...@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.
Index:
testsuite/21_strings/basic_string_view/requirements/constexpr_iter.cc
===================================================================
---
testsuite/21_strings/basic_string_view/requirements/constexpr_iter.cc
(nonexistent)
+++
testsuite/21_strings/basic_string_view/requirements/constexpr_iter.cc
(working copy)
@@ -0,0 +1,43 @@
+// { dg-do compile { target c++2a } }
Please check the testsuite/libstdc++.log or testsuite/libstdc++.sum
files for the new tests. I expect they are both UNSUPPORTED.
That's because you've given a target c++2a which means they won't be
run unless a suitable -std option is given. And you haven't given one.
You need to add { dg-options "-std=gnu++2a" } before the dg-do line.
Also if the tests are restricted to C++2a then there's no point having
the #if __cplusplus > 201703L check, because that will never be false.
I had supplied the option for gnu++2a by hand and they passed.?? They
were not UNSUPPORTED.
I just added the dg-options (at very top) and reran the testsuite
without fancy tricks (except for gnu++2a).
I also took out the #if __cplusplus.?? I was just playing around and
discovered that these pass in C++17 if you comment out the C++20
constexpr algos.
OK for trunk?
OK for trunk.
Committed 272084.
Also, we could declare victory for this for gcc-9.?? May I backport
after this is in?
Yes, these tests are also OK to backport to gcc-9-branch (assuming
they pass on the branch, which I agree they should do).
Thanks!
The backport is the same less the calls to std::copy. CL and patch
attached. Committed 272097.
Ed
2019-06-09 Edward Smith-Rowland <3dw...@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.
Index: testsuite/21_strings/basic_string_view/requirements/constexpr_iter.cc
===================================================================
--- testsuite/21_strings/basic_string_view/requirements/constexpr_iter.cc
(nonexistent)
+++ testsuite/21_strings/basic_string_view/requirements/constexpr_iter.cc
(working copy)
@@ -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();
+}
Index: testsuite/23_containers/array/requirements/constexpr_iter.cc
===================================================================
--- testsuite/23_containers/array/requirements/constexpr_iter.cc
(nonexistent)
+++ testsuite/23_containers/array/requirements/constexpr_iter.cc
(working copy)
@@ -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();
+}