Implement C++20 constexpr <algorithm>, , and <array>

Ed Smith-Rowland via libstdc++ libstdc++@gcc.gnu.org
Tue Mar 19 22:15:00 GMT 2019


On 3/19/19 4:57 PM, Ed Smith-Rowland via libstdc++ wrote:
> On 3/18/19 6:18 PM, Jonathan Wakely wrote:
>> On 17/03/19 22:54 -0400, Ed Smith-Rowland via libstdc++ wrote:
>>> Greetings,
>>>
>>> This patch implements C++20 p0202 - Add Constexpr Modifiers to 
>>> Functions in <algorithm> and <utility> Headers
>>>
>>> and C++20 p1023 - constexpr comparison operators for std::array.
>>>
>>>
>>> The patch is large because of the testsuite additions. Basically, 
>>> the algorithms and the array comparison operators are all marked 
>>> constexpr for C++20.  This has been built and tested on x86_64-linux.
>>
>> As discussed on IRC< the tests need to be run with -std=gnu++2a to
>> ensure everything we test (which is not exhaustive, but is the best we
>> can do) still works in C++2a mode.
>>
>> The indentation went bad here:
>>
>>   template<typename _FIter1, typename _FIter2, typename 
>> _BinaryPredicate>
>> -    _FIter1
>> +    _GLIBCXX20_CONSTEXPR
>> +   _FIter1
>>     find_first_of(_FIter1, _FIter1, _FIter2, _FIter2, _BinaryPredicate);
> Fixed.
>>
>> I would have to look through old emails but I think there's a reason
>> the function objects like _Iter_comp_to_val take their arguments by
>> non-const reference.
>>
>> I'm very surprised that none of the algos that dispatch to
>> __builtin_memove need changes, because those optimizations won't work
>> in constant expressions. I would expect to have to use
>> std::is_constant_evaluated to disable the optimizations when used in
>> constant expressions.
>>
> As am I. As I mentioned on IRC I could roll a constexpr memmove.
>
> I was wondering if somehow I'm not checking what I think I'm checking 
> (but I don't see how.)
>
> I wonder if the builtins are handled differently somehow by the front 
> end.  I'm still not sure why __builtin_memcmp is OK for array == array 
> but not array != array.  In that case I just do element by element 
> compare for constexpr now anyway.
>
> Ed

Ignore this patch,

I'm not actually getting constexpr.

Ed




More information about the Libstdc++ mailing list