diff mbox series

Test for C++20 p0858 - ConstexprIterator requirements.

Message ID a16d4ac2-f12e-d3a7-4593-aa9dd490ee1f@verizon.net
State New
Headers show
Series Test for C++20 p0858 - ConstexprIterator requirements. | expand

Commit Message

Li, Pan2 via Gcc-patches May 31, 2019, 10:24 p.m. UTC
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.

Ed
2019-06-03  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.

Comments

Ville Voutilainen May 31, 2019, 10:29 p.m. UTC | #1
On Sat, 1 Jun 2019 at 01:24, Ed Smith-Rowland via libstdc++
<libstdc++@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?
Li, Pan2 via Gcc-patches June 1, 2019, 6:09 p.m. UTC | #2
On 5/31/19 6:29 PM, Ville Voutilainen wrote:
> On Sat, 1 Jun 2019 at 01:24, Ed Smith-Rowland via libstdc++
> <libstdc++@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.

Also, instead of bool variables I put the checks in static_asserts.

I return functions of (derefed) iterators.

I made it so we could run these at C++17 if we want to with '#if 
__cplusplus == 201703L' the algorithm usage for C++20 only.?? This wasn't 
a DR though.

Anyway, that should do it.

Built and tested clean on x86_64-linux. Ok?

Ed
2019-06-03  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.
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,37 @@
+// { 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));
+
+#if __cplusplus > 201703L
+  std::array<int, hw.size()> a2{{0,0,0,0,0,0,0,0,0,0,0,0,0}};
+  std::copy(hw.begin(), hw.end(), a2.begin());
+#endif
+
+  return *(hw.cbegin() + 3);
+}
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,36 @@
+// { 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());
+
+#if __cplusplus > 201703L
+  std::array<int, 3> a2{{0, 0, 0}};
+  std::copy(a1.begin(), a1.end(), a2.begin());
+#endif
+
+  return n;
+}
Ville Voutilainen June 1, 2019, 6:42 p.m. UTC | #3
On Sat, 1 Jun 2019 at 21:09, Ed Smith-Rowland <3dw4rd@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++
> > <libstdc++@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();
}
Li, Pan2 via Gcc-patches June 1, 2019, 7:40 p.m. UTC | #4
On 6/1/19 2:42 PM, Ville Voutilainen wrote:
> On Sat, 1 Jun 2019 at 21:09, Ed Smith-Rowland <3dw4rd@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++
>>> <libstdc++@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  <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.
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 } }
+//
+// 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));
+
+#if __cplusplus > 201703L
+  std::array<int, hw.size()> a2{{0,0,0,0,0,0,0,0,0,0,0,0,0}};
+  std::copy(hw.begin(), hw.end(), a2.begin());
+#endif
+
+  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,42 @@
+// { 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());
+
+#if __cplusplus > 201703L
+  std::array<int, 3> a2{{0, 0, 0}};
+  std::copy(a1.begin(), a1.end(), a2.begin());
+#endif
+
+  return n;
+}
+
+void
+run_test()
+{
+  constexpr int n = test();
+}
Ville Voutilainen June 1, 2019, 7:49 p.m. UTC | #5
On Sat, 1 Jun 2019 at 22:40, Ed Smith-Rowland <3dw4rd@verizon.net> wrote:

> 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.

Looks good. Jonathan needs to approve it, though.

> But static_assert is a constexpr context no?

Yes, it is. It's just that now all of test() is verified to be okay as
a constant expression, including std::copy.
Jonathan Wakely June 7, 2019, 3:42 p.m. UTC | #6
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 <3dw4rd@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++
>>>><libstdc++@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  <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.
>

>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.
Jonathan Wakely June 7, 2019, 7:57 p.m. UTC | #7
On 07/06/19 16:42 +0100, 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 <3dw4rd@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++
>>>>><libstdc++@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  <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.
>>
>
>>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've enhanced my badtests.awk script to check for this case, and it
found a problem with 24_iterators/container_access.cc (the dg-options
needs to be first or the -std option isn't used when checking the
effective target).

Tested x86_64-linux, committed to trunk.
Li, Pan2 via Gcc-patches June 8, 2019, 4:05 p.m. UTC | #8
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 <3dw4rd@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++
>>>>> <libstdc++@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 <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.
>>
>
>> 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?

Also, we could declare victory for this for gcc-9.?? May I backport after 
this is in?

Ed
2019-06-10  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.
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,42 @@
+// { 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));
+
+  std::array<int, hw.size()> a2{{0,0,0,0,0,0,0,0,0,0,0,0,0}};
+  std::copy(hw.begin(), hw.end(), a2.begin());
+
+  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,41 @@
+// { 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());
+
+  std::array<int, 3> a2{{0, 0, 0}};
+  std::copy(a1.begin(), a1.end(), a2.begin());
+
+  return n;
+}
+
+void
+run_test()
+{
+  constexpr int n = test();
+}
Jonathan Wakely June 8, 2019, 8:28 p.m. UTC | #9
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 
>>>><3dw4rd@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++
>>>>>><libstdc++@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 <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.
>>>
>>
>>>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.

>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!
Li, Pan2 via Gcc-patches June 9, 2019, 9:54 p.m. UTC | #10
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 <3dw4rd@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++
>>>>>>> <libstdc++@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 <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.
>>>>
>>>
>>>> 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  <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.
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();
+}
Rainer Orth June 9, 2019, 10:03 p.m. UTC | #11
Hi Ed,

>>> 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.

272085 actually ;-)  Unfortunately, the new tests seem to FAIL (almost?)
everywhere:

+FAIL: 21_strings/basic_string_view/requirements/constexpr_iter.cc (test for excess errors)

Excess errors:
/vol/gcc/src/hg/trunk/local/libstdc++-v3/testsuite/21_strings/basic_string_view/requirements/constexpr_iter.cc:33: error: call to non-'constexpr' function '_OI std::copy(_II, _II, _OI) [with _II = const char*; _OI = int*]'
/vol/gcc/src/hg/trunk/local/libstdc++-v3/testsuite/21_strings/basic_string_view/requirements/constexpr_iter.cc:41: error: 'constexpr char test()' called in a constant expression

+FAIL: 23_containers/array/requirements/constexpr_iter.cc (test for excess errors)

/vol/gcc/src/hg/trunk/local/libstdc++-v3/testsuite/23_containers/array/requirements/constexpr_iter.cc:32: error: call to non-'constexpr' function '_OI std::copy(_II, _II, _OI) [with _II = const int*; _OI = int*]'
/vol/gcc/src/hg/trunk/local/libstdc++-v3/testsuite/23_containers/array/requirements/constexpr_iter.cc:40: error: 'constexpr int test()' called in a constant expression

I'm seeing those on i386-pc-solaris2.11 and sparc-sun-solaris2.11, and
there are gcc-testresults reports on aarch64-unknown-linux-gnu,
i686-pc-linux-gnu, powerpc64le-unknown-linux-gnu, and
x86_64-pc-linux-gnu, among others.

Please fix.

	Rainer
Ville Voutilainen June 9, 2019, 10:28 p.m. UTC | #12
On Mon, 10 Jun 2019 at 01:03, Rainer Orth <ro@cebitec.uni-bielefeld.de> wrote:
>
> Hi Ed,
>
> >>> 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.
>
> 272085 actually ;-)  Unfortunately, the new tests seem to FAIL (almost?)
> everywhere:
>
> +FAIL: 21_strings/basic_string_view/requirements/constexpr_iter.cc (test for excess errors)
>
> Excess errors:
> /vol/gcc/src/hg/trunk/local/libstdc++-v3/testsuite/21_strings/basic_string_view/requirements/constexpr_iter.cc:33: error: call to non-'constexpr' function '_OI std::copy(_II, _II, _OI) [with _II = const char*; _OI = int*]'
> /vol/gcc/src/hg/trunk/local/libstdc++-v3/testsuite/21_strings/basic_string_view/requirements/constexpr_iter.cc:41: error: 'constexpr char test()' called in a constant expression
>
> +FAIL: 23_containers/array/requirements/constexpr_iter.cc (test for excess errors)
>
> /vol/gcc/src/hg/trunk/local/libstdc++-v3/testsuite/23_containers/array/requirements/constexpr_iter.cc:32: error: call to non-'constexpr' function '_OI std::copy(_II, _II, _OI) [with _II = const int*; _OI = int*]'
> /vol/gcc/src/hg/trunk/local/libstdc++-v3/testsuite/23_containers/array/requirements/constexpr_iter.cc:40: error: 'constexpr int test()' called in a constant expression
>
> I'm seeing those on i386-pc-solaris2.11 and sparc-sun-solaris2.11, and
> there are gcc-testresults reports on aarch64-unknown-linux-gnu,
> i686-pc-linux-gnu, powerpc64le-unknown-linux-gnu, and
> x86_64-pc-linux-gnu, among others.
>
> Please fix.

Indeed. std::copy isn't constexpr yet. I don't see how Ed's test run
can pass. We either need to put this on hold until enough of
<algorithm> is constexprified,
or we need to use loops in this test and test (constexpr) algorithms'
use of (constexpr) iterators separately later.
Jonathan Wakely June 9, 2019, 10:28 p.m. UTC | #13
On 10/06/19 00:03 +0200, Rainer Orth wrote:
>Hi Ed,
>
>>>> 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.
>
>272085 actually ;-)  Unfortunately, the new tests seem to FAIL (almost?)
>everywhere:
>
>+FAIL: 21_strings/basic_string_view/requirements/constexpr_iter.cc (test for excess errors)
>
>Excess errors:
>/vol/gcc/src/hg/trunk/local/libstdc++-v3/testsuite/21_strings/basic_string_view/requirements/constexpr_iter.cc:33: error: call to non-'constexpr' function '_OI std::copy(_II, _II, _OI) [with _II = const char*; _OI = int*]'
>/vol/gcc/src/hg/trunk/local/libstdc++-v3/testsuite/21_strings/basic_string_view/requirements/constexpr_iter.cc:41: error: 'constexpr char test()' called in a constant expression
>
>+FAIL: 23_containers/array/requirements/constexpr_iter.cc (test for excess errors)
>
>/vol/gcc/src/hg/trunk/local/libstdc++-v3/testsuite/23_containers/array/requirements/constexpr_iter.cc:32: error: call to non-'constexpr' function '_OI std::copy(_II, _II, _OI) [with _II = const int*; _OI = int*]'
>/vol/gcc/src/hg/trunk/local/libstdc++-v3/testsuite/23_containers/array/requirements/constexpr_iter.cc:40: error: 'constexpr int test()' called in a constant expression
>
>I'm seeing those on i386-pc-solaris2.11 and sparc-sun-solaris2.11, and
>there are gcc-testresults reports on aarch64-unknown-linux-gnu,
>i686-pc-linux-gnu, powerpc64le-unknown-linux-gnu, and
>x86_64-pc-linux-gnu, among others.

Presumably because std::copy isn't actually constexpr yet.

Ed, do you have uncommitted local changes that allow this test to
pass? Because I don't see how it can pass otherwise.
Li, Pan2 via Gcc-patches June 9, 2019, 11:53 p.m. UTC | #14
On 6/9/19 6:28 PM, Jonathan Wakely wrote:
> On 10/06/19 00:03 +0200, Rainer Orth wrote:
>> Hi Ed,
>>
>>>>> 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.
>>
>> 272085 actually ;-)?? Unfortunately, the new tests seem to FAIL (almost?)
>> everywhere:
>>
>> +FAIL: 21_strings/basic_string_view/requirements/constexpr_iter.cc 
>> (test for excess errors)
>>
>> Excess errors:
>> /vol/gcc/src/hg/trunk/local/libstdc++-v3/testsuite/21_strings/basic_string_view/requirements/constexpr_iter.cc:33: 
>> error: call to non-'constexpr' function '_OI std::copy(_II, _II, _OI) 
>> [with _II = const char*; _OI = int*]'
>> /vol/gcc/src/hg/trunk/local/libstdc++-v3/testsuite/21_strings/basic_string_view/requirements/constexpr_iter.cc:41: 
>> error: 'constexpr char test()' called in a constant expression
>>
>> +FAIL: 23_containers/array/requirements/constexpr_iter.cc (test for 
>> excess errors)
>>
>> /vol/gcc/src/hg/trunk/local/libstdc++-v3/testsuite/23_containers/array/requirements/constexpr_iter.cc:32: 
>> error: call to non-'constexpr' function '_OI std::copy(_II, _II, _OI) 
>> [with _II = const int*; _OI = int*]'
>> /vol/gcc/src/hg/trunk/local/libstdc++-v3/testsuite/23_containers/array/requirements/constexpr_iter.cc:40: 
>> error: 'constexpr int test()' called in a constant expression
>>
>> I'm seeing those on i386-pc-solaris2.11 and sparc-sun-solaris2.11, and
>> there are gcc-testresults reports on aarch64-unknown-linux-gnu,
>> i686-pc-linux-gnu, powerpc64le-unknown-linux-gnu, and
>> x86_64-pc-linux-gnu, among others.
>
> Presumably because std::copy isn't actually constexpr yet.
>
> Ed, do you have uncommitted local changes that allow this test to
> pass? Because I don't see how it can pass otherwise.
>
Darn it, I had those constexpr lib patches in tree.

Attached are what I just committed to gcc-9 and passes there. Those 
std::copy didn't really add anything anyway.

Note to self - no matter how small work on a separate branch.

I'm testing on a new clean branch unless someone beats me to it.

Sorry for all the noise.

Ed
Index: testsuite/21_strings/basic_string_view/requirements/constexpr_iter.cc
===================================================================
--- testsuite/21_strings/basic_string_view/requirements/constexpr_iter.cc	(revision 272098)
+++ testsuite/21_strings/basic_string_view/requirements/constexpr_iter.cc	(working copy)
@@ -29,9 +29,6 @@
   auto ch = hw[4];
   static_assert('W' == *(hw.cbegin() + 7));
 
-  std::array<int, hw.size()> a2{{0,0,0,0,0,0,0,0,0,0,0,0,0}};
-  std::copy(hw.begin(), hw.end(), a2.begin());
-
   return *(hw.cbegin() + 3);
 }
 
Index: testsuite/23_containers/array/requirements/constexpr_iter.cc
===================================================================
--- testsuite/23_containers/array/requirements/constexpr_iter.cc	(revision 272098)
+++ testsuite/23_containers/array/requirements/constexpr_iter.cc	(working copy)
@@ -28,9 +28,6 @@
   auto n = a1[0] * a1[1]* a1[2];
   static_assert(1 == *a1.cbegin());
 
-  std::array<int, 3> a2{{0, 0, 0}};
-  std::copy(a1.begin(), a1.end(), a2.begin());
-
   return n;
 }
Ville Voutilainen June 10, 2019, 6:43 a.m. UTC | #15
On Mon, 10 Jun 2019 at 02:53, Ed Smith-Rowland <3dw4rd@verizon.net> wrote:

> Darn it, I had those constexpr lib patches in tree.
> Attached are what I just committed to gcc-9 and passes there. Those
> std::copy didn't really add anything anyway.

They added a test that *i++ = *j++ works, and that i != j works.
Li, Pan2 via Gcc-patches June 10, 2019, 10:46 p.m. UTC | #16
On 6/10/19 2:43 AM, Ville Voutilainen wrote:
> On Mon, 10 Jun 2019 at 02:53, Ed Smith-Rowland <3dw4rd@verizon.net> wrote:
>
>> Darn it, I had those constexpr lib patches in tree.
>> Attached are what I just committed to gcc-9 and passes there. Those
>> std::copy didn't really add anything anyway.
> They added a test that *i++ = *j++ works, and that i != j works.
>
Ok,

Here is a version that adds back a hand written copy thing to test 
Ville's observation.

This is tested on a clean branch.

I would also like to add the same copy lines to the gcc-9 branch.

OK?

Ed
2019-06-11  Edward Smith-Rowland  <3dw4rd@verizon.net>

	Test 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.
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
index 24ab502372a..799fb0391f5 100644
--- 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
@@ -30,7 +30,11 @@ test()
   static_assert('W' == *(hw.cbegin() + 7));
 
   std::array<int, hw.size()> a2{{0,0,0,0,0,0,0,0,0,0,0,0,0}};
-  std::copy(hw.begin(), hw.end(), a2.begin());
+  auto hwi = hw.begin();
+  auto hwe = hw.end();
+  auto a2i = a2.begin();
+  while (hwi != hwe)
+    *a2i++ = *hwi++;
 
   return *(hw.cbegin() + 3);
 }
diff --git a/libstdc++-v3/testsuite/23_containers/array/requirements/constexpr_iter.cc b/libstdc++-v3/testsuite/23_containers/array/requirements/constexpr_iter.cc
index 88d69d2f8c7..4b5346631c9 100644
--- a/libstdc++-v3/testsuite/23_containers/array/requirements/constexpr_iter.cc
+++ b/libstdc++-v3/testsuite/23_containers/array/requirements/constexpr_iter.cc
@@ -27,9 +27,13 @@ test()
   static_assert(1 == *a1.begin());
   auto n = a1[0] * a1[1]* a1[2];
   static_assert(1 == *a1.cbegin());
-
+ 
   std::array<int, 3> a2{{0, 0, 0}};
-  std::copy(a1.begin(), a1.end(), a2.begin());
+  auto a1i = a1.begin();
+  auto a1e = a1.end();
+  auto a2i = a2.begin();
+  while (a1i != a1e)
+    *a2i++ = *a1i++;
 
   return n;
 }
Jonathan Wakely June 11, 2019, 8:48 a.m. UTC | #17
On 10/06/19 18:46 -0400, Ed Smith-Rowland via libstdc++ wrote:
>On 6/10/19 2:43 AM, Ville Voutilainen wrote:
>>On Mon, 10 Jun 2019 at 02:53, Ed Smith-Rowland <3dw4rd@verizon.net> wrote:
>>
>>>Darn it, I had those constexpr lib patches in tree.
>>>Attached are what I just committed to gcc-9 and passes there. Those
>>>std::copy didn't really add anything anyway.
>>They added a test that *i++ = *j++ works, and that i != j works.
>>
>Ok,
>
>Here is a version that adds back a hand written copy thing to test 
>Ville's observation.
>
>This is tested on a clean branch.
>
>I would also like to add the same copy lines to the gcc-9 branch.
>
>OK?

Ok for trunk and gcc-9-branch, thanks.
diff mbox series

Patch

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,33 @@ 
+// { 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>
+
+void
+test()
+{
+  constexpr std::string_view hw("Hello, World!");
+  bool ok = 'H' == *hw.begin();
+  auto ch = hw[4];
+  bool cok = 'W' == *(hw.cbegin() + 7);
+
+  std::array<int, hw.size()> a2{{0,0,0,0,0,0,0,0,0,0,0,0,0}};
+  std::copy(hw.begin(), hw.end(), a2.begin());
+}
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,32 @@ 
+// { 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>
+
+void
+test()
+{
+  constexpr std::array<int, 3> a1{{1, 2, 3}};
+  bool ok = 1 == *a1.begin();
+  auto n = a1[0] * a1[1]* a1[2];
+  bool cok = 1 == *a1.cbegin();
+
+  std::array<int, 3> a2{{0, 0, 0}};
+  std::copy(a1.begin(), a1.end(), a2.begin());
+}