Test for C++20 p0858 - ConstexprIterator requirements.

Jonathan Wakely jwakely@redhat.com
Fri Jun 7 19:57:00 GMT 2019


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.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch.txt
Type: text/x-patch
Size: 809 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20190607/ee557b4b/attachment.bin>


More information about the Libstdc++ mailing list