public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 1/3] C++20 constexpr lib part 1/3
@ 2019-06-26 23:13 Ed Smith-Rowland via gcc-patches
  2019-06-27 15:41 ` Jonathan Wakely
  2019-07-02 12:11 ` Jonathan Wakely
  0 siblings, 2 replies; 22+ messages in thread
From: Ed Smith-Rowland via gcc-patches @ 2019-06-26 23:13 UTC (permalink / raw)
  To: Jonathan Wakely, libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 679 bytes --]

Here is the first of three patches for C++20 constexpr library.

 ?????? Implement C++20 p0202 - Add constexpr Modifiers to Functions in 
<algorithm> and <utility> Headers.
 ???? ??Implement C++20 p1023 - constexpr comparison operators for std::array.

I believe I have answered peoples concerns with the last patch attempts 
[https://gcc.gnu.org/ml/libstdc++/2019-03/msg00132.html].

The patch is large because of test cases but really just boils down to 
adding constexpr for c++2a.

The patch passes testing for gnu++2a and pre-gnu++2a on x86_64-linux:

$ make check -k -j4

$ make check RUNTESTFLAGS=--target_board=unix/-std=gnu++2a -k -j4

OK for trunk?

Ed Smith-Rowland



[-- Attachment #2: CL_constexpr_lib --]
[-- Type: text/plain, Size: 7088 bytes --]

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

	Implement C++20 p0202 - Add Constexpr Modifiers to Functions
	in <algorithm> and <utility> Headers.
	Implement C++20 p1023 - constexpr comparison operators for std::array.
	* include/bits/algorithmfwd.h (all_of, any_of, binary_search, copy,
	copy_backward, copy_if, copy_n, equal_range, fill, find_end,
	find_if_not, includes, is_heap, is_heap_until, is_partitioned,
	is_permutation, is_sorted, is_sorted_until, iter_swap, lower_bound,
	none_of, partition_copy, partition_point, remove, remove_if,
	remove_copy, remove_copy_if, replace_copy, replace_copy_if,
	reverse_copy, rotate_copy, uunique, upper_bound, adjacent_find, count,
	count_if, equal, find, find_first_of, find_if, for_each, generate,
	generate_n, lexicographical_compare, merge, mismatch, replace,
	replace_if, search, search_n, set_difference, set_intersection,
	set_symmetric_difference, set_union, transform, unique_copy):
	Mark constexpr.
	* include/bits/cpp_type_traits.h (__miter_base): Mark constexpr.
	* include/bits/predefined_ops.h (_Iter_less_val::operator(),
	_Val_less_iter::operator(), _Iter_equal_to_iter::operator(),
	_Iter_equal_to_val::operator(), _Iter_equals_val::operator()):
	 Use const ref instead of ref arg;
	(_Iter_less_val, __iter_less_val, _Val_less_iter, __val_less_iter,
	__iter_equal_to_iter, __iter_equal_to_val, __iter_comp_val,
	_Iter_comp_val, _Val_comp_iter, __val_comp_iter, __iter_equals_val,
	_Iter_equals_iter, __iter_comp_iter, _Iter_pred, __pred_iter,
	_Iter_comp_to_val, __iter_comp_val, _Iter_comp_to_iter,
	__iter_comp_iter): Mark constexpr.
	* include/bits/stl_algo.h (__find_if, __find_if_not, __find_if_not_n,
	__search, __search_n_aux, __search_n, __find_end, find_end, all_of,
	none_of, any_of, find_if_not, is_partitioned, partition_point,
	__remove_copy_if, remove_copy, remove_copy_if, copy_if, __copy_n,
	copy_n, partition_copy, __remove_if, remove, remove_if, __adjacent_find,
	__unique, unique, __unique_copy, reverse_copy, rotate_copy,
	__unguarded_linear_insert, __insertion_sort, __unguarded_insertion_sort,
	__final_insertion_sort, lower_bound, __upper_bound, upper_bound,
	__equal_range, equal_range, binary_search, __includes, includes,
	__next_permutation, __prev_permutation, __replace_copy_if, replace_copy,
	replace_copy_if, __count_if, is_sorted, __is_sorted_until,
	is_sorted_until, __is_permutation, is_permutation, for_each, find,
	find_if, find_first_of, adjacent_find, count, count_if, search,
	search_n, transform, replace, replace_if, generate, generate_n,
	unique_copy, __merge, merge, __set_union, set_union, __set_intersection,
	set_intersection, __set_difference, set_difference,
	__set_symmetric_difference, set_symmetric_difference):  Mark constexpr.
	* include/bits/stl_algobase.h (__memmove, __memcmp): New maybe constexpr
	wrappers around __builtin_memmove and __builtin_memcmp
	respectively;
	(__niter_base, __niter_wrap, __copy_m, __copy_move_a, __copy_move_a2,
	copy, move, __copy_move_b, __copy_move_backward_a,
	__copy_move_backward_a2, copy_backward, move_backward, __fill_a, fill,
	__fill_n_a, fill_n, equal, __lc_rai::__newlast1, __lc_rai::__cnd2,
	__lexicographical_compare_impl, __lexicographical_compare,
	__lexicographical_compare<true>::__lc, __lexicographical_compare_aux,
	__lower_bound, lower_bound, equal, __equal4, lexicographical_compare,
	__mismatch, mismatch, __is_heap_until, __is_heap, is_heap_until,
	is_heap): Mark constexpr.
	* include/bits/stl_heap.h (__is_heap_until, __is_heap, is_heap_until,
	is_heap): Mark constexpr.
	* include/bits/stl_iterator.h (__niter_base, __miter_base): Mark constexpr.
	* include/std/array: Make comparison ops constexpr.
	* include/std/utility: Make exchange constexpr.
	* testsuite/23_containers/array/tuple_interface/get_neg.cc: Adjust.
	* testsuite/23_containers/array/tuple_interface/
	tuple_element_neg.cc: Adjust.
	* testsuite/20_util/exchange/constexpr.cc: New.
	* testsuite/23_containers/array/comparison_operators/constexpr.cc: New.
	* testsuite/25_algorithms/adjacent_find/constexpr.cc: New.
	* testsuite/25_algorithms/all_of/constexpr.cc: New.
	* testsuite/25_algorithms/any_of/constexpr.cc: New.
	* testsuite/25_algorithms/binary_search/constexpr.cc: New.
	* testsuite/25_algorithms/copy/constexpr.cc: New.
	* testsuite/25_algorithms/copy_backward/constexpr.cc: New.
	* testsuite/25_algorithms/copy_if/constexpr.cc: New.
	* testsuite/25_algorithms/copy_n/constexpr.cc: New.
	* testsuite/25_algorithms/count/constexpr.cc: New.
	* testsuite/25_algorithms/count_if/constexpr.cc: New.
	* testsuite/25_algorithms/equal/constexpr.cc: New.
	* testsuite/25_algorithms/equal_range/constexpr.cc: New.
	* testsuite/25_algorithms/fill/constexpr.cc: New.
	* testsuite/25_algorithms/fill_n/constexpr.cc: New.
	* testsuite/25_algorithms/find/constexpr.cc: New.
	* testsuite/25_algorithms/find_end/constexpr.cc: New.
	* testsuite/25_algorithms/find_first_of/constexpr.cc: New.
	* testsuite/25_algorithms/find_if/constexpr.cc: New.
	* testsuite/25_algorithms/find_if_not/constexpr.cc: New.
	* testsuite/25_algorithms/for_each/constexpr.cc: New.
	* testsuite/25_algorithms/generate/constexpr.cc: New.
	* testsuite/25_algorithms/generate_n/constexpr.cc: New.
	* testsuite/25_algorithms/is_heap/constexpr.cc: New.
	* testsuite/25_algorithms/is_heap_until/constexpr.cc: New.
	* testsuite/25_algorithms/is_partitioned/constexpr.cc: New.
	* testsuite/25_algorithms/is_permutation/constexpr.cc: New.
	* testsuite/25_algorithms/is_sorted/constexpr.cc: New.
	* testsuite/25_algorithms/is_sorted_until/constexpr.cc: New.
	* testsuite/25_algorithms/lexicographical_compare/constexpr.cc: New.
	* testsuite/25_algorithms/lower_bound/constexpr.cc: New.
	* testsuite/25_algorithms/merge/constexpr.cc: New.
	* testsuite/25_algorithms/mismatch/constexpr.cc: New.
	* testsuite/25_algorithms/none_of/constexpr.cc: New.
	* testsuite/25_algorithms/partition_copy/constexpr.cc: New.
	* testsuite/25_algorithms/partition_point/constexpr.cc: New.
	* testsuite/25_algorithms/remove/constexpr.cc: New.
	* testsuite/25_algorithms/remove_copy/constexpr.cc: New.
	* testsuite/25_algorithms/remove_copy_if/constexpr.cc: New.
	* testsuite/25_algorithms/remove_if/constexpr.cc: New.
	* testsuite/25_algorithms/replace_copy/constexpr.cc: New.
	* testsuite/25_algorithms/replace_copy_if/constexpr.cc: New.
	* testsuite/25_algorithms/replace_if/constexpr.cc: New.
	* testsuite/25_algorithms/reverse_copy/constexpr.cc: New.
	* testsuite/25_algorithms/rotate_copy/constexpr.cc: New.
	* testsuite/25_algorithms/search/constexpr.cc: New.
	* testsuite/25_algorithms/search_n/constexpr.cc: New.
	* testsuite/25_algorithms/set_difference/constexpr.cc: New.
	* testsuite/25_algorithms/set_intersection/constexpr.cc: New.
	* testsuite/25_algorithms/set_symmetric_difference/constexpr.cc: New.
	* testsuite/25_algorithms/set_union/constexpr.cc: New.
	* testsuite/25_algorithms/transform/constexpr.cc: New.
	* testsuite/25_algorithms/unique/constexpr.cc: New.
	* testsuite/25_algorithms/unique_copy/constexpr.cc: New.
	* testsuite/25_algorithms/upper_bound/constexpr.cc: New.

[-- Attachment #3: patch_constexpr_lib.bz2 --]
[-- Type: application/x-bzip, Size: 13576 bytes --]

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH 1/3] C++20 constexpr lib part 1/3
  2019-06-26 23:13 [PATCH 1/3] C++20 constexpr lib part 1/3 Ed Smith-Rowland via gcc-patches
@ 2019-06-27 15:41 ` Jonathan Wakely
  2019-06-27 16:54   ` Ed Smith-Rowland via gcc-patches
  2019-07-02 12:11 ` Jonathan Wakely
  1 sibling, 1 reply; 22+ messages in thread
From: Jonathan Wakely @ 2019-06-27 15:41 UTC (permalink / raw)
  To: Ed Smith-Rowland; +Cc: libstdc++, gcc-patches

On 26/06/19 19:13 -0400, Ed Smith-Rowland via libstdc++ wrote:
>Here is the first of three patches for C++20 constexpr library.
>
>?????? Implement C++20 p0202 - Add constexpr Modifiers to Functions in 
><algorithm> and <utility> Headers.
>???? ??Implement C++20 p1023 - constexpr comparison operators for std::array.
>
>I believe I have answered peoples concerns with the last patch 
>attempts [https://gcc.gnu.org/ml/libstdc++/2019-03/msg00132.html].
>
>The patch is large because of test cases but really just boils down to 
>adding constexpr for c++2a.

I still have some concerns about the changes like:

     template<typename _Iterator, typename _Value>
+      _GLIBCXX20_CONSTEXPR
       bool
-      operator()(_Iterator __it, _Value& __val) const
+      operator()(_Iterator __it, const _Value& __val) const
       { return *__it < __val; }


I think that might change semantics for some types, and I haven't yet
figured out if we care about those cases or not. I'll try to come up
with some examples that change meaning.

This could use _GLIBCXX14_CONSTEXPR:

+  /**
+   * A constexpr wrapper for __builtin_memmove.
+   * @param __num The number of elements of type _Tp (not bytes).

I don't think we want a Doxygen comment for this, as it's not part of
the public API. Just a normal comment is fine.

+   */
+  template<bool _IsMove, typename _Tp>
+    _GLIBCXX20_CONSTEXPR
+    inline void*
+    __memmove(_Tp* __dst, const _Tp* __src, size_t __num)
+    {
+#if __cplusplus > 201703L \
+    && defined(_GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED)
+      if (__builtin_is_constant_evaluated())
+	{
+	  for(; __num > 0; --__num)
+	    {
+	      if constexpr (_IsMove)
+		*__dst = std::move(*__src);
+	      else
+		*__dst = *__src;

Do we need this _IsMove condition here? We should only be using this
function for trivially copyable types, in which case copy vs move
shouldn't matter, should it?

Oh ... is it because we also end up using this __memmove function for
non-trivially copyable types, during constant evaluation? Hmm. Then
it's more than just a wrapper for __builtin_memmove, right? It's
"either memmove or constexpr range copy", or something.

I don't think this will work in a constant expression:

   /// Assign @p __new_val to @p __obj and return its previous value.
   template <typename _Tp, typename _Up = _Tp>
+    _GLIBCXX20_CONSTEXPR
     inline _Tp
     exchange(_Tp& __obj, _Up&& __new_val)
     { return std::__exchange(__obj, std::forward<_Up>(__new_val)); }

Because std::__exchange hasn't been marked constexpr. The test passes
because it doesn't call it in a context that requires constant
evaluation:

  const auto x = std::exchange(e, pi);

I see the same problem in other tests too:

+  constexpr std::array<int, 12> car{{0, 1, 2, 3, 4, 5, 6, 6, 8, 9, 9, 11}};
+
+  const auto out0x = std::adjacent_find(car.begin(), car.end());
+
+  const auto out1x = std::adjacent_find(car.begin(), car.end(),
+					std::equal_to<int>());



^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH 1/3] C++20 constexpr lib part 1/3
  2019-06-27 15:41 ` Jonathan Wakely
@ 2019-06-27 16:54   ` Ed Smith-Rowland via gcc-patches
  2019-06-27 17:06     ` Ville Voutilainen
  0 siblings, 1 reply; 22+ messages in thread
From: Ed Smith-Rowland via gcc-patches @ 2019-06-27 16:54 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: libstdc++, gcc-patches

On 6/27/19 11:41 AM, Jonathan Wakely wrote:
> On 26/06/19 19:13 -0400, Ed Smith-Rowland via libstdc++ wrote:
>> Here is the first of three patches for C++20 constexpr library.
>>
>> ?????? Implement C++20 p0202 - Add constexpr Modifiers to Functions 
>> in <algorithm> and <utility> Headers.
>> ???? ??Implement C++20 p1023 - constexpr comparison operators for 
>> std::array.
>>
>> I believe I have answered peoples concerns with the last patch 
>> attempts [https://gcc.gnu.org/ml/libstdc++/2019-03/msg00132.html].
>>
>> The patch is large because of test cases but really just boils down 
>> to adding constexpr for c++2a.
>
> I still have some concerns about the changes like:
>
> ?????? template<typename _Iterator, typename _Value>
> +?????????? _GLIBCXX20_CONSTEXPR
> ?????????? bool
> -?????????? operator()(_Iterator __it, _Value& __val) const
> +?????????? operator()(_Iterator __it, const _Value& __val) const
> ?????????? { return *__it < __val; }
>
Make a type where operator< changes the rhs.?? I was thinking you'd want 
a compare to operate on const things but I guess we have to be ready for 
anything.?? I was also thinking < is left associative for a class member 
but i guess a class could have a thing that mutates the rhs too.?? 
Nothing got hit in any of my testing.?? If this is a thing we probably 
should make a general test for things like this somewhere.?? Maybe 
someone wants to log references or something.

1. I'll experiment to see if I really need these (I *thought* I did, but...)

2. If I still do then I'll make overloads?

>
> I think that might change semantics for some types, and I haven't yet
> figured out if we care about those cases or not. I'll try to come up
> with some examples that change meaning.
>
> This could use _GLIBCXX14_CONSTEXPR:
>
> +?? /**
> +???? * A constexpr wrapper for __builtin_memmove.
> +???? * @param __num The number of elements of type _Tp (not bytes).
>
> I don't think we want a Doxygen comment for this, as it's not part of
> the public API. Just a normal comment is fine.
>
> +???? */
> +?? template<bool _IsMove, typename _Tp>
> +?????? _GLIBCXX20_CONSTEXPR
> +?????? inline void*
> +?????? __memmove(_Tp* __dst, const _Tp* __src, size_t __num)
> +?????? {
> +#if __cplusplus > 201703L \
> +?????? && defined(_GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED)
> +?????????? if (__builtin_is_constant_evaluated())
> +?????? {
> +?????????? for(; __num > 0; --__num)
> +?????????????? {
> +?????????????????? if constexpr (_IsMove)
> +?????????????? *__dst = std::move(*__src);
> +?????????????????? else
> +?????????????? *__dst = *__src;
>
> Do we need this _IsMove condition here? We should only be using this
> function for trivially copyable types, in which case copy vs move
> shouldn't matter, should it?
>
> Oh ... is it because we also end up using this __memmove function for
> non-trivially copyable types, during constant evaluation? Hmm. Then
> it's more than just a wrapper for __builtin_memmove, right? It's
> "either memmove or constexpr range copy", or something.

Yup.?? I'm also bad at naming things.?? Furthermore, I expect the 
standards people to want to have our versions of memcpy, memcmp, memmove 
that we own and can make constexpr.?? These are such important concepts.

Also, part 2 brings in constexpr swap. Maybe this is the may to 
implement an actual memmove?

>
> I don't think this will work in a constant expression:
>
> ?? /// Assign @p __new_val to @p __obj and return its previous value.
> ?? template <typename _Tp, typename _Up = _Tp>
> +?????? _GLIBCXX20_CONSTEXPR
> ?????? inline _Tp
> ?????? exchange(_Tp& __obj, _Up&& __new_val)
> ?????? { return std::__exchange(__obj, std::forward<_Up>(__new_val)); }
>
> Because std::__exchange hasn't been marked constexpr. The test passes
> because it doesn't call it in a context that requires constant
> evaluation:
>
> ??const auto x = std::exchange(e, pi);
Derp.
>
> I see the same problem in other tests too:
>
> +?? constexpr std::array<int, 12> car{{0, 1, 2, 3, 4, 5, 6, 6, 8, 9, 9, 
> 11}};
> +
> +?? const auto out0x = std::adjacent_find(car.begin(), car.end());
> +
> +?? const auto out1x = std::adjacent_find(car.begin(), car.end(),
> +?????????????????????????????????????? std::equal_to<int>())

I will go through all the tests and make sure that some nontrivial 
calculation is done that contributes to a final bool return.?? And clean 
up the mess.?? I did this in chunk 2 but I guess I left a lot of chunk 1.

Come to think of it, we could build *insane* concepts after this.?? For 
good or ill.

Ed

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH 1/3] C++20 constexpr lib part 1/3
  2019-06-27 16:54   ` Ed Smith-Rowland via gcc-patches
@ 2019-06-27 17:06     ` Ville Voutilainen
  2019-06-27 23:07       ` Ed Smith-Rowland via gcc-patches
  0 siblings, 1 reply; 22+ messages in thread
From: Ville Voutilainen @ 2019-06-27 17:06 UTC (permalink / raw)
  To: Ed Smith-Rowland; +Cc: Jonathan Wakely, libstdc++, gcc-patches

On Thu, 27 Jun 2019 at 19:55, Ed Smith-Rowland via libstdc++
<libstdc++@gcc.gnu.org> wrote:
> > I don't think this will work in a constant expression:
> >
> > ?? /// Assign @p __new_val to @p __obj and return its previous value.
> > ?? template <typename _Tp, typename _Up = _Tp>
> > +?????? _GLIBCXX20_CONSTEXPR
> > ?????? inline _Tp
> > ?????? exchange(_Tp& __obj, _Up&& __new_val)
> > ?????? { return std::__exchange(__obj, std::forward<_Up>(__new_val)); }
> >
> > Because std::__exchange hasn't been marked constexpr. The test passes
> > because it doesn't call it in a context that requires constant
> > evaluation:
> >
> > ??const auto x = std::exchange(e, pi);
> Derp.
> >
> > I see the same problem in other tests too:
> >
> > +?? constexpr std::array<int, 12> car{{0, 1, 2, 3, 4, 5, 6, 6, 8, 9, 9,
> > 11}};
> > +
> > +?? const auto out0x = std::adjacent_find(car.begin(), car.end());
> > +
> > +?? const auto out1x = std::adjacent_find(car.begin(), car.end(),
> > +?????????????????????????????????????? std::equal_to<int>())
>
> I will go through all the tests and make sure that some nontrivial
> calculation is done that contributes to a final bool return.?? And clean
> up the mess.?? I did this in chunk 2 but I guess I left a lot of chunk 1.

As was the case with the iterator patch, it's not a question of doing
a nontrivial calculation, but
a question of initializing a constexpr variable with the result. (Yeah
sure a non-type template
argument would also work but eurgh). Then, and only then, have we
proven that the code
works in a constexpr context. Initializing a const doesn't do that.
constinit would, but that's
C++20.

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH 1/3] C++20 constexpr lib part 1/3
  2019-06-27 17:06     ` Ville Voutilainen
@ 2019-06-27 23:07       ` Ed Smith-Rowland via gcc-patches
  2019-06-27 23:31         ` Jonathan Wakely
  0 siblings, 1 reply; 22+ messages in thread
From: Ed Smith-Rowland via gcc-patches @ 2019-06-27 23:07 UTC (permalink / raw)
  To: Ville Voutilainen; +Cc: Jonathan Wakely, libstdc++, gcc-patches

On 6/27/19 1:06 PM, Ville Voutilainen wrote:
> On Thu, 27 Jun 2019 at 19:55, Ed Smith-Rowland via libstdc++
> <libstdc++@gcc.gnu.org> wrote:
>>> I don't think this will work in a constant expression:
>>>
>>> ?? /// Assign @p __new_val to @p __obj and return its previous value.
>>> ?? template <typename _Tp, typename _Up = _Tp>
>>> +?????? _GLIBCXX20_CONSTEXPR
>>> ?????? inline _Tp
>>> ?????? exchange(_Tp& __obj, _Up&& __new_val)
>>> ?????? { return std::__exchange(__obj, std::forward<_Up>(__new_val)); }
>>>
>>> Because std::__exchange hasn't been marked constexpr. The test passes
>>> because it doesn't call it in a context that requires constant
>>> evaluation:
>>>
>>> ??const auto x = std::exchange(e, pi);
>> Derp.
>>> I see the same problem in other tests too:
>>>
>>> +?? constexpr std::array<int, 12> car{{0, 1, 2, 3, 4, 5, 6, 6, 8, 9, 9,
>>> 11}};
>>> +
>>> +?? const auto out0x = std::adjacent_find(car.begin(), car.end());
>>> +
>>> +?? const auto out1x = std::adjacent_find(car.begin(), car.end(),
>>> +?????????????????????????????????????? std::equal_to<int>())
>> I will go through all the tests and make sure that some nontrivial
>> calculation is done that contributes to a final bool return.?? And clean
>> up the mess.?? I did this in chunk 2 but I guess I left a lot of chunk 1.
> As was the case with the iterator patch, it's not a question of doing
> a nontrivial calculation, but
> a question of initializing a constexpr variable with the result. (Yeah
> sure a non-type template
> argument would also work but eurgh). Then, and only then, have we
> proven that the code
> works in a constexpr context. Initializing a const doesn't do that.
> constinit would, but that's
> C++20.
>
Ok, why isn't

 ?? static_assert(test());

a constexpr context?

The std::exchange test passed originally because, unlike all the other 
algo tests I had neglected to call the test function in a constexpr context.

Note that constexpr_iter.c is this:

----

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}};
 ?? auto a1i = a1.begin();
 ?? auto a1e = a1.end();
 ?? auto a2i = a2.begin();
 ?? while (a1i != a1e)
 ?????? *a2i++ = *a1i++;

 ?? return n;
}

void
run_test()
{
 ?? constexpr int n = test();
}

----

Things inside the function can, and in many cases for this capability 
must, be mutable.?? As long as the input and the final output is a 
literal we should be good, no?

Also when I assign returned iterators to constexpr I get:

/home/ed/gcc_git/libstdc++-v3/testsuite/25_algorithms/find_if_not/constexpr.cc:36: 
error: '(((std::array<int, 12>::const_pointer)(& ca0.std::array<int, 
12>::_M_elems)) + 28)' is not a constant expression.

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH 1/3] C++20 constexpr lib part 1/3
  2019-06-27 23:07       ` Ed Smith-Rowland via gcc-patches
@ 2019-06-27 23:31         ` Jonathan Wakely
  0 siblings, 0 replies; 22+ messages in thread
From: Jonathan Wakely @ 2019-06-27 23:31 UTC (permalink / raw)
  To: Ed Smith-Rowland; +Cc: Ville Voutilainen, libstdc++, gcc-patches

On 27/06/19 19:07 -0400, Ed Smith-Rowland wrote:
>On 6/27/19 1:06 PM, Ville Voutilainen wrote:
>>On Thu, 27 Jun 2019 at 19:55, Ed Smith-Rowland via libstdc++
>><libstdc++@gcc.gnu.org> wrote:
>>>>I don't think this will work in a constant expression:
>>>>
>>>>?? /// Assign @p __new_val to @p __obj and return its previous value.
>>>>?? template <typename _Tp, typename _Up = _Tp>
>>>>+?????? _GLIBCXX20_CONSTEXPR
>>>>?????? inline _Tp
>>>>?????? exchange(_Tp& __obj, _Up&& __new_val)
>>>>?????? { return std::__exchange(__obj, std::forward<_Up>(__new_val)); }
>>>>
>>>>Because std::__exchange hasn't been marked constexpr. The test passes
>>>>because it doesn't call it in a context that requires constant
>>>>evaluation:
>>>>
>>>>??const auto x = std::exchange(e, pi);
>>>Derp.
>>>>I see the same problem in other tests too:
>>>>
>>>>+?? constexpr std::array<int, 12> car{{0, 1, 2, 3, 4, 5, 6, 6, 8, 9, 9,
>>>>11}};
>>>>+
>>>>+?? const auto out0x = std::adjacent_find(car.begin(), car.end());
>>>>+
>>>>+?? const auto out1x = std::adjacent_find(car.begin(), car.end(),
>>>>+?????????????????????????????????????? std::equal_to<int>())
>>>I will go through all the tests and make sure that some nontrivial
>>>calculation is done that contributes to a final bool return.?? And clean
>>>up the mess.?? I did this in chunk 2 but I guess I left a lot of chunk 1.
>>As was the case with the iterator patch, it's not a question of doing
>>a nontrivial calculation, but
>>a question of initializing a constexpr variable with the result. (Yeah
>>sure a non-type template
>>argument would also work but eurgh). Then, and only then, have we
>>proven that the code
>>works in a constexpr context. Initializing a const doesn't do that.
>>constinit would, but that's
>>C++20.
>>
>Ok, why isn't
>
>?? static_assert(test());
>
>a constexpr context?

It is, I missed that the array test does that at the bottom of the
file.


>The std::exchange test passed originally because, unlike all the other 
>algo tests I had neglected to call the test function in a constexpr 
>context.
>
>Note that constexpr_iter.c is this:
>
>----
>
>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}};
>?? auto a1i = a1.begin();
>?? auto a1e = a1.end();
>?? auto a2i = a2.begin();
>?? while (a1i != a1e)
>?????? *a2i++ = *a1i++;
>
>?? return n;
>}
>
>void
>run_test()
>{
>?? constexpr int n = test();
>}
>
>----
>
>Things inside the function can, and in many cases for this capability 
>must, be mutable.?? As long as the input and the final output is a 
>literal we should be good, no?
>
>Also when I assign returned iterators to constexpr I get:
>
>/home/ed/gcc_git/libstdc++-v3/testsuite/25_algorithms/find_if_not/constexpr.cc:36: 
>error: '(((std::array<int, 12>::const_pointer)(& ca0.std::array<int, 
>12>::_M_elems)) + 28)' is not a constant expression.

Yes, I tried adding that and got the same error, which is why I
thought the test had the same problem as the std::exchange one.

I'm not sure what causes that error, I'll take a look tomorrow.


^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH 1/3] C++20 constexpr lib part 1/3
  2019-06-26 23:13 [PATCH 1/3] C++20 constexpr lib part 1/3 Ed Smith-Rowland via gcc-patches
  2019-06-27 15:41 ` Jonathan Wakely
@ 2019-07-02 12:11 ` Jonathan Wakely
  2019-07-06  7:55   ` Ed Smith-Rowland via gcc-patches
  1 sibling, 1 reply; 22+ messages in thread
From: Jonathan Wakely @ 2019-07-02 12:11 UTC (permalink / raw)
  To: Ed Smith-Rowland; +Cc: libstdc++, gcc-patches

On 26/06/19 19:13 -0400, Ed Smith-Rowland via libstdc++ wrote:
>Here is the first of three patches for C++20 constexpr library.
>
>?????? Implement C++20 p0202 - Add constexpr Modifiers to Functions in 
><algorithm> and <utility> Headers.
>???? ??Implement C++20 p1023 - constexpr comparison operators for std::array.
>
>I believe I have answered peoples concerns with the last patch 
>attempts [https://gcc.gnu.org/ml/libstdc++/2019-03/msg00132.html].
>
>The patch is large because of test cases but really just boils down to 
>adding constexpr for c++2a.
>
>The patch passes testing for gnu++2a and pre-gnu++2a on x86_64-linux:
>
>$ make check -k -j4
>
>$ make check RUNTESTFLAGS=--target_board=unix/-std=gnu++2a -k -j4
>
>OK for trunk?

One more comment. In <bits/stl_algobase.h> this:

+#if __cplusplus > 201703L \
+    && defined(_GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED)
+      if (__builtin_is_constant_evaluated())

can be simplified to just:

#ifdef __cpp_lib_is_constant_evaluated
      if (std::is_constant_evaluated())

The feature test macro is exactly the check we want here.


^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH 1/3] C++20 constexpr lib part 1/3
  2019-07-02 12:11 ` Jonathan Wakely
@ 2019-07-06  7:55   ` Ed Smith-Rowland via gcc-patches
  2019-07-06  8:01     ` Ville Voutilainen
  0 siblings, 1 reply; 22+ messages in thread
From: Ed Smith-Rowland via gcc-patches @ 2019-07-06  7:55 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 4055 bytes --]

On 7/2/19 8:11 AM, Jonathan Wakely wrote:
> One more comment. In <bits/stl_algobase.h> this:
>
> +#if __cplusplus > 201703L \
> +?????? && defined(_GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED)
> +?????????? if (__builtin_is_constant_evaluated())
>
> can be simplified to just:
>
> #ifdef __cpp_lib_is_constant_evaluated
> ???????? if (std::is_constant_evaluated())
>
> The feature test macro is exactly the check we want here

This is done and the test cases for the non-modifying algorithms are done.

I'm was stumped on the modifying algos though.?? Consider std::copy:

-------------------------------------

constexpr bool
test()
{
 ?? constexpr std::array<int, 12> ca0{{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 
11}};
 ?? std::array<int, 12> ma0{{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};

 ?? constexpr auto out6 = std::copy(ca0.begin(), ca0.begin() + 8, 
ma0.begin() + 2);

 ?? return out6 == ma0.begin() + 10;
}

static_assert(test());
-------------------------------------

This is essentially the same as the Boost test case referenced in p0202.

I've also taken the arrays out as globals with the same result either way:

-------------------------------------

ed@bad-horse:~/cxx_constexpr_lib$ ../bin_constexpr_lib/bin/g++ 
-std=gnu++2a -c testsuite/25_algorithms/copy/constexpr.cc
testsuite/25_algorithms/copy/constexpr.cc: In function ???constexpr bool 
test()???:
testsuite/25_algorithms/copy/constexpr.cc:36:34:???? in ???constexpr??? 
expansion of ???std::copy<const int*, int*>(ca0.std::array<int, 
12>::begin(), (ca0.std::array<int, 12>::begin() + 32), 
(ma0.std::array<int, 12>::begin() + 8))???
/home/ed/bin_constexpr_lib/include/c++/10.0.0/bits/stl_algobase.h:535:7: 
in ???constexpr??? expansion of ???std::__copy_move_a2<false, const int*, 
int*>(std::__miter_base<const int*>(__first), std::__miter_base<const 
int*>(__last), __result)???
/home/ed/bin_constexpr_lib/include/c++/10.0.0/bits/stl_algobase.h:501:30: 
in ???constexpr??? expansion of ???std::__copy_move_a<false, const int*, 
int*>(std::__niter_base<const int*>(__first), std::__niter_base<const 
int*>(__last), std::__niter_base<int*>(__result))???
/home/ed/bin_constexpr_lib/include/c++/10.0.0/bits/stl_algobase.h:463:30: 
in ???constexpr??? expansion of ???std::__copy_move<false, true, 
std::random_access_iterator_tag>::__copy_m<int>(__first, __last, __result)???
/home/ed/bin_constexpr_lib/include/c++/10.0.0/bits/stl_algobase.h:445:24: 
in ???constexpr??? expansion of ???std::__memmove<false, int>(__result, 
__first, ((std::size_t)((std::ptrdiff_t)_Num)))???
testsuite/25_algorithms/copy/constexpr.cc:36:80: error: modification of 
???ma0??? is not a constant expression
 ???? 36 |???? constexpr auto out6 = std::copy(ca0.begin(), ca0.begin() + 8, 
ma0.begin() + 2);
| ^
testsuite/25_algorithms/copy/constexpr.cc: At global scope:
testsuite/25_algorithms/copy/constexpr.cc:41:19: error: non-constant 
condition for static assertion
 ???? 41 | static_assert(test());
 ?????????? |???????????????????????????? ~~~~^~

-------------------------------------

By my reckoning, you have a constexpr source array, an output array that 
is initialized as it must be for constexpr.?? You have to have a 
deterministic result after the copy.?? In the local array version the 
actual iterator is not leaking out - just the results of a calculation 
that must return one result.

The only thing that 'helps' is removing the constexpr from the iterator 
return and of course that's the whole point of the thing.

Blargh!

So, you can't modify a constexpr sequence. No actual surprise.?? The 
returned iterators into non-constexpr sequences can never be literals.?? 
What you *can* do is make the modifying algorithms so you can make pure 
functions with them.?? In this connection my previous testcases for 
non-modifying?? were correct, just not complete because there the 
returned iterators into constexpr sequences can be (must be) literals.

So here is a new patch for chunk 1 of constexpr library.

Tested with default settings and with -std=gnu++2a on x86_64-linux.

OK?

Ed



[-- Attachment #2: CL_constexpr_lib --]
[-- Type: text/plain, Size: 7088 bytes --]

2019-07-08  Edward Smith-Rowland  <3dw4rd@verizon.net>

	Implement C++20 p0202 - Add Constexpr Modifiers to Functions
	in <algorithm> and <utility> Headers.
	Implement C++20 p1023 - constexpr comparison operators for std::array.
	* include/bits/algorithmfwd.h (all_of, any_of, binary_search, copy,
	copy_backward, copy_if, copy_n, equal_range, fill, find_end,
	find_if_not, includes, is_heap, is_heap_until, is_partitioned,
	is_permutation, is_sorted, is_sorted_until, iter_swap, lower_bound,
	none_of, partition_copy, partition_point, remove, remove_if,
	remove_copy, remove_copy_if, replace_copy, replace_copy_if,
	reverse_copy, rotate_copy, uunique, upper_bound, adjacent_find, count,
	count_if, equal, find, find_first_of, find_if, for_each, generate,
	generate_n, lexicographical_compare, merge, mismatch, replace,
	replace_if, search, search_n, set_difference, set_intersection,
	set_symmetric_difference, set_union, transform, unique_copy):
	Mark constexpr.
	* include/bits/cpp_type_traits.h (__miter_base): Mark constexpr.
	* include/bits/predefined_ops.h (_Iter_less_val::operator(),
	_Val_less_iter::operator(), _Iter_equal_to_iter::operator(),
	_Iter_equal_to_val::operator(), _Iter_equals_val::operator()):
	 Use const ref instead of ref arg;
	(_Iter_less_val, __iter_less_val, _Val_less_iter, __val_less_iter,
	__iter_equal_to_iter, __iter_equal_to_val, __iter_comp_val,
	_Iter_comp_val, _Val_comp_iter, __val_comp_iter, __iter_equals_val,
	_Iter_equals_iter, __iter_comp_iter, _Iter_pred, __pred_iter,
	_Iter_comp_to_val, __iter_comp_val, _Iter_comp_to_iter,
	__iter_comp_iter): Mark constexpr.
	* include/bits/stl_algo.h (__find_if, __find_if_not, __find_if_not_n,
	__search, __search_n_aux, __search_n, __find_end, find_end, all_of,
	none_of, any_of, find_if_not, is_partitioned, partition_point,
	__remove_copy_if, remove_copy, remove_copy_if, copy_if, __copy_n,
	copy_n, partition_copy, __remove_if, remove, remove_if, __adjacent_find,
	__unique, unique, __unique_copy, reverse_copy, rotate_copy,
	__unguarded_linear_insert, __insertion_sort, __unguarded_insertion_sort,
	__final_insertion_sort, lower_bound, __upper_bound, upper_bound,
	__equal_range, equal_range, binary_search, __includes, includes,
	__next_permutation, __prev_permutation, __replace_copy_if, replace_copy,
	replace_copy_if, __count_if, is_sorted, __is_sorted_until,
	is_sorted_until, __is_permutation, is_permutation, for_each, find,
	find_if, find_first_of, adjacent_find, count, count_if, search,
	search_n, transform, replace, replace_if, generate, generate_n,
	unique_copy, __merge, merge, __set_union, set_union, __set_intersection,
	set_intersection, __set_difference, set_difference,
	__set_symmetric_difference, set_symmetric_difference):  Mark constexpr.
	* include/bits/stl_algobase.h (__memmove, __memcmp): New maybe constexpr
	wrappers around __builtin_memmove and __builtin_memcmp
	respectively;
	(__niter_base, __niter_wrap, __copy_m, __copy_move_a, __copy_move_a2,
	copy, move, __copy_move_b, __copy_move_backward_a,
	__copy_move_backward_a2, copy_backward, move_backward, __fill_a, fill,
	__fill_n_a, fill_n, equal, __lc_rai::__newlast1, __lc_rai::__cnd2,
	__lexicographical_compare_impl, __lexicographical_compare,
	__lexicographical_compare<true>::__lc, __lexicographical_compare_aux,
	__lower_bound, lower_bound, equal, __equal4, lexicographical_compare,
	__mismatch, mismatch, __is_heap_until, __is_heap, is_heap_until,
	is_heap): Mark constexpr.
	* include/bits/stl_heap.h (__is_heap_until, __is_heap, is_heap_until,
	is_heap): Mark constexpr.
	* include/bits/stl_iterator.h (__niter_base, __miter_base): Mark constexpr.
	* include/std/array: Make comparison ops constexpr.
	* include/std/utility: Make exchange constexpr.
	* testsuite/23_containers/array/tuple_interface/get_neg.cc: Adjust.
	* testsuite/23_containers/array/tuple_interface/
	tuple_element_neg.cc: Adjust.
	* testsuite/20_util/exchange/constexpr.cc: New.
	* testsuite/23_containers/array/comparison_operators/constexpr.cc: New.
	* testsuite/25_algorithms/adjacent_find/constexpr.cc: New.
	* testsuite/25_algorithms/all_of/constexpr.cc: New.
	* testsuite/25_algorithms/any_of/constexpr.cc: New.
	* testsuite/25_algorithms/binary_search/constexpr.cc: New.
	* testsuite/25_algorithms/copy/constexpr.cc: New.
	* testsuite/25_algorithms/copy_backward/constexpr.cc: New.
	* testsuite/25_algorithms/copy_if/constexpr.cc: New.
	* testsuite/25_algorithms/copy_n/constexpr.cc: New.
	* testsuite/25_algorithms/count/constexpr.cc: New.
	* testsuite/25_algorithms/count_if/constexpr.cc: New.
	* testsuite/25_algorithms/equal/constexpr.cc: New.
	* testsuite/25_algorithms/equal_range/constexpr.cc: New.
	* testsuite/25_algorithms/fill/constexpr.cc: New.
	* testsuite/25_algorithms/fill_n/constexpr.cc: New.
	* testsuite/25_algorithms/find/constexpr.cc: New.
	* testsuite/25_algorithms/find_end/constexpr.cc: New.
	* testsuite/25_algorithms/find_first_of/constexpr.cc: New.
	* testsuite/25_algorithms/find_if/constexpr.cc: New.
	* testsuite/25_algorithms/find_if_not/constexpr.cc: New.
	* testsuite/25_algorithms/for_each/constexpr.cc: New.
	* testsuite/25_algorithms/generate/constexpr.cc: New.
	* testsuite/25_algorithms/generate_n/constexpr.cc: New.
	* testsuite/25_algorithms/is_heap/constexpr.cc: New.
	* testsuite/25_algorithms/is_heap_until/constexpr.cc: New.
	* testsuite/25_algorithms/is_partitioned/constexpr.cc: New.
	* testsuite/25_algorithms/is_permutation/constexpr.cc: New.
	* testsuite/25_algorithms/is_sorted/constexpr.cc: New.
	* testsuite/25_algorithms/is_sorted_until/constexpr.cc: New.
	* testsuite/25_algorithms/lexicographical_compare/constexpr.cc: New.
	* testsuite/25_algorithms/lower_bound/constexpr.cc: New.
	* testsuite/25_algorithms/merge/constexpr.cc: New.
	* testsuite/25_algorithms/mismatch/constexpr.cc: New.
	* testsuite/25_algorithms/none_of/constexpr.cc: New.
	* testsuite/25_algorithms/partition_copy/constexpr.cc: New.
	* testsuite/25_algorithms/partition_point/constexpr.cc: New.
	* testsuite/25_algorithms/remove/constexpr.cc: New.
	* testsuite/25_algorithms/remove_copy/constexpr.cc: New.
	* testsuite/25_algorithms/remove_copy_if/constexpr.cc: New.
	* testsuite/25_algorithms/remove_if/constexpr.cc: New.
	* testsuite/25_algorithms/replace_copy/constexpr.cc: New.
	* testsuite/25_algorithms/replace_copy_if/constexpr.cc: New.
	* testsuite/25_algorithms/replace_if/constexpr.cc: New.
	* testsuite/25_algorithms/reverse_copy/constexpr.cc: New.
	* testsuite/25_algorithms/rotate_copy/constexpr.cc: New.
	* testsuite/25_algorithms/search/constexpr.cc: New.
	* testsuite/25_algorithms/search_n/constexpr.cc: New.
	* testsuite/25_algorithms/set_difference/constexpr.cc: New.
	* testsuite/25_algorithms/set_intersection/constexpr.cc: New.
	* testsuite/25_algorithms/set_symmetric_difference/constexpr.cc: New.
	* testsuite/25_algorithms/set_union/constexpr.cc: New.
	* testsuite/25_algorithms/transform/constexpr.cc: New.
	* testsuite/25_algorithms/unique/constexpr.cc: New.
	* testsuite/25_algorithms/unique_copy/constexpr.cc: New.
	* testsuite/25_algorithms/upper_bound/constexpr.cc: New.

[-- Attachment #3: patch_constexpr_lib_2.bz2 --]
[-- Type: application/x-bzip, Size: 14941 bytes --]

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH 1/3] C++20 constexpr lib part 1/3
  2019-07-06  7:55   ` Ed Smith-Rowland via gcc-patches
@ 2019-07-06  8:01     ` Ville Voutilainen
  2019-07-11 16:48       ` Ed Smith-Rowland via gcc-patches
  2019-07-31 15:00       ` Ed Smith-Rowland via gcc-patches
  0 siblings, 2 replies; 22+ messages in thread
From: Ville Voutilainen @ 2019-07-06  8:01 UTC (permalink / raw)
  To: Ed Smith-Rowland; +Cc: Jonathan Wakely, libstdc++, gcc-patches

On Sat, 6 Jul 2019 at 06:12, Ed Smith-Rowland via libstdc++
<libstdc++@gcc.gnu.org> wrote:
> By my reckoning, you have a constexpr source array, an output array that
> is initialized as it must be for constexpr.?? You have to have a
> deterministic result after the copy.?? In the local array version the
> actual iterator is not leaking out - just the results of a calculation
> that must return one result.
>
> The only thing that 'helps' is removing the constexpr from the iterator
> return and of course that's the whole point of the thing.
>
> Blargh!

But that's fine; the result of copy is not stored in a constexpr
variable, but the function return
is static_asserted so we have sufficiently tested that std::copy is
indeed constexpr-compatible
since it appears in a function that is evaluated at compile-time.

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH 1/3] C++20 constexpr lib part 1/3
  2019-07-06  8:01     ` Ville Voutilainen
@ 2019-07-11 16:48       ` Ed Smith-Rowland via gcc-patches
  2019-07-31 15:00       ` Ed Smith-Rowland via gcc-patches
  1 sibling, 0 replies; 22+ messages in thread
From: Ed Smith-Rowland via gcc-patches @ 2019-07-11 16:48 UTC (permalink / raw)
  To: Ville Voutilainen; +Cc: Jonathan Wakely, libstdc++, gcc-patches

On 7/6/19 3:55 AM, Ville Voutilainen wrote:
>> Blargh!
> But that's fine; the result of copy is not stored in a constexpr
> variable, but the function return
> is static_asserted so we have sufficiently tested that std::copy is
> indeed constexpr-compatible
> since it appears in a function that is evaluated at compile-time.

Ping?

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH 1/3] C++20 constexpr lib part 1/3
  2019-07-06  8:01     ` Ville Voutilainen
  2019-07-11 16:48       ` Ed Smith-Rowland via gcc-patches
@ 2019-07-31 15:00       ` Ed Smith-Rowland via gcc-patches
  2019-08-01 10:56         ` Jonathan Wakely
  1 sibling, 1 reply; 22+ messages in thread
From: Ed Smith-Rowland via gcc-patches @ 2019-07-31 15:00 UTC (permalink / raw)
  To: Ville Voutilainen; +Cc: Jonathan Wakely, libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 506 bytes --]

Here is the patch for

* Implement C++20 p0202 - Add constexpr Modifiers to Functions in 
<algorithm> and <utility> Headers.

* Implement C++20 p1023 - constexpr comparison operators for std::array.

Relative to the last effort it is rebased on more recent trunk and I 
added to <version>.

There's some chance that I'll have to tweak the macros after the draft 
comes in but I'd like to get this moving.?? I've got other chunks of 
constexpr lib coming.?? This passes C++20 testing onx86_64-linux.

Ok?



[-- Attachment #2: CL_constexpr_lib --]
[-- Type: text/plain, Size: 7145 bytes --]

2019-07-31  Edward Smith-Rowland  <3dw4rd@verizon.net>

	Implement C++20 p0202 - Add Constexpr Modifiers to Functions
	in <algorithm> and <utility> Headers.
	Implement C++20 p1023 - constexpr comparison operators for std::array.
	* include/bits/algorithmfwd.h (all_of, any_of, binary_search, copy,
	copy_backward, copy_if, copy_n, equal_range, fill, find_end,
	find_if_not, includes, is_heap, is_heap_until, is_partitioned,
	is_permutation, is_sorted, is_sorted_until, iter_swap, lower_bound,
	none_of, partition_copy, partition_point, remove, remove_if,
	remove_copy, remove_copy_if, replace_copy, replace_copy_if,
	reverse_copy, rotate_copy, uunique, upper_bound, adjacent_find, count,
	count_if, equal, find, find_first_of, find_if, for_each, generate,
	generate_n, lexicographical_compare, merge, mismatch, replace,
	replace_if, search, search_n, set_difference, set_intersection,
	set_symmetric_difference, set_union, transform, unique_copy):
	Mark constexpr.
	* include/bits/cpp_type_traits.h (__miter_base): Mark constexpr.
	* include/bits/predefined_ops.h (_Iter_less_val::operator(),
	_Val_less_iter::operator(), _Iter_equal_to_iter::operator(),
	_Iter_equal_to_val::operator(), _Iter_equals_val::operator()):
	 Use const ref instead of ref arg;
	(_Iter_less_val, __iter_less_val, _Val_less_iter, __val_less_iter,
	__iter_equal_to_iter, __iter_equal_to_val, __iter_comp_val,
	_Iter_comp_val, _Val_comp_iter, __val_comp_iter, __iter_equals_val,
	_Iter_equals_iter, __iter_comp_iter, _Iter_pred, __pred_iter,
	_Iter_comp_to_val, __iter_comp_val, _Iter_comp_to_iter,
	__iter_comp_iter): Mark constexpr.
	* include/bits/stl_algo.h (__find_if, __find_if_not, __find_if_not_n,
	__search, __search_n_aux, __search_n, __find_end, find_end, all_of,
	none_of, any_of, find_if_not, is_partitioned, partition_point,
	__remove_copy_if, remove_copy, remove_copy_if, copy_if, __copy_n,
	copy_n, partition_copy, __remove_if, remove, remove_if, __adjacent_find,
	__unique, unique, __unique_copy, reverse_copy, rotate_copy,
	__unguarded_linear_insert, __insertion_sort, __unguarded_insertion_sort,
	__final_insertion_sort, lower_bound, __upper_bound, upper_bound,
	__equal_range, equal_range, binary_search, __includes, includes,
	__next_permutation, __prev_permutation, __replace_copy_if, replace_copy,
	replace_copy_if, __count_if, is_sorted, __is_sorted_until,
	is_sorted_until, __is_permutation, is_permutation, for_each, find,
	find_if, find_first_of, adjacent_find, count, count_if, search,
	search_n, transform, replace, replace_if, generate, generate_n,
	unique_copy, __merge, merge, __set_union, set_union, __set_intersection,
	set_intersection, __set_difference, set_difference,
	__set_symmetric_difference, set_symmetric_difference):  Mark constexpr.
	* include/bits/stl_algobase.h (__memmove, __memcmp): New maybe constexpr
	wrappers around __builtin_memmove and __builtin_memcmp
	respectively;
	(__niter_base, __niter_wrap, __copy_m, __copy_move_a, __copy_move_a2,
	copy, move, __copy_move_b, __copy_move_backward_a,
	__copy_move_backward_a2, copy_backward, move_backward, __fill_a, fill,
	__fill_n_a, fill_n, equal, __lc_rai::__newlast1, __lc_rai::__cnd2,
	__lexicographical_compare_impl, __lexicographical_compare,
	__lexicographical_compare<true>::__lc, __lexicographical_compare_aux,
	__lower_bound, lower_bound, equal, __equal4, lexicographical_compare,
	__mismatch, mismatch, __is_heap_until, __is_heap, is_heap_until,
	is_heap): Mark constexpr.
	* include/bits/stl_heap.h (__is_heap_until, __is_heap, is_heap_until,
	is_heap): Mark constexpr.
	* include/bits/stl_iterator.h (__niter_base, __miter_base): Mark constexpr.
	* include/std/array: Make comparison ops constexpr.
	* include/std/utility: Make exchange constexpr.
	* include/std/version (__cpp_lib_constexpr): New macro.
	* testsuite/23_containers/array/tuple_interface/get_neg.cc: Adjust.
	* testsuite/23_containers/array/tuple_interface/
	tuple_element_neg.cc: Adjust.
	* testsuite/20_util/exchange/constexpr.cc: New.
	* testsuite/23_containers/array/comparison_operators/constexpr.cc: New.
	* testsuite/25_algorithms/adjacent_find/constexpr.cc: New.
	* testsuite/25_algorithms/all_of/constexpr.cc: New.
	* testsuite/25_algorithms/any_of/constexpr.cc: New.
	* testsuite/25_algorithms/binary_search/constexpr.cc: New.
	* testsuite/25_algorithms/copy/constexpr.cc: New.
	* testsuite/25_algorithms/copy_backward/constexpr.cc: New.
	* testsuite/25_algorithms/copy_if/constexpr.cc: New.
	* testsuite/25_algorithms/copy_n/constexpr.cc: New.
	* testsuite/25_algorithms/count/constexpr.cc: New.
	* testsuite/25_algorithms/count_if/constexpr.cc: New.
	* testsuite/25_algorithms/equal/constexpr.cc: New.
	* testsuite/25_algorithms/equal_range/constexpr.cc: New.
	* testsuite/25_algorithms/fill/constexpr.cc: New.
	* testsuite/25_algorithms/fill_n/constexpr.cc: New.
	* testsuite/25_algorithms/find/constexpr.cc: New.
	* testsuite/25_algorithms/find_end/constexpr.cc: New.
	* testsuite/25_algorithms/find_first_of/constexpr.cc: New.
	* testsuite/25_algorithms/find_if/constexpr.cc: New.
	* testsuite/25_algorithms/find_if_not/constexpr.cc: New.
	* testsuite/25_algorithms/for_each/constexpr.cc: New.
	* testsuite/25_algorithms/generate/constexpr.cc: New.
	* testsuite/25_algorithms/generate_n/constexpr.cc: New.
	* testsuite/25_algorithms/is_heap/constexpr.cc: New.
	* testsuite/25_algorithms/is_heap_until/constexpr.cc: New.
	* testsuite/25_algorithms/is_partitioned/constexpr.cc: New.
	* testsuite/25_algorithms/is_permutation/constexpr.cc: New.
	* testsuite/25_algorithms/is_sorted/constexpr.cc: New.
	* testsuite/25_algorithms/is_sorted_until/constexpr.cc: New.
	* testsuite/25_algorithms/lexicographical_compare/constexpr.cc: New.
	* testsuite/25_algorithms/lower_bound/constexpr.cc: New.
	* testsuite/25_algorithms/merge/constexpr.cc: New.
	* testsuite/25_algorithms/mismatch/constexpr.cc: New.
	* testsuite/25_algorithms/none_of/constexpr.cc: New.
	* testsuite/25_algorithms/partition_copy/constexpr.cc: New.
	* testsuite/25_algorithms/partition_point/constexpr.cc: New.
	* testsuite/25_algorithms/remove/constexpr.cc: New.
	* testsuite/25_algorithms/remove_copy/constexpr.cc: New.
	* testsuite/25_algorithms/remove_copy_if/constexpr.cc: New.
	* testsuite/25_algorithms/remove_if/constexpr.cc: New.
	* testsuite/25_algorithms/replace_copy/constexpr.cc: New.
	* testsuite/25_algorithms/replace_copy_if/constexpr.cc: New.
	* testsuite/25_algorithms/replace_if/constexpr.cc: New.
	* testsuite/25_algorithms/reverse_copy/constexpr.cc: New.
	* testsuite/25_algorithms/rotate_copy/constexpr.cc: New.
	* testsuite/25_algorithms/search/constexpr.cc: New.
	* testsuite/25_algorithms/search_n/constexpr.cc: New.
	* testsuite/25_algorithms/set_difference/constexpr.cc: New.
	* testsuite/25_algorithms/set_intersection/constexpr.cc: New.
	* testsuite/25_algorithms/set_symmetric_difference/constexpr.cc: New.
	* testsuite/25_algorithms/set_union/constexpr.cc: New.
	* testsuite/25_algorithms/transform/constexpr.cc: New.
	* testsuite/25_algorithms/unique/constexpr.cc: New.
	* testsuite/25_algorithms/unique_copy/constexpr.cc: New.
	* testsuite/25_algorithms/upper_bound/constexpr.cc: New.

[-- Attachment #3: patch_constexpr_lib_3.bz2 --]
[-- Type: application/x-bzip, Size: 15017 bytes --]

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH 1/3] C++20 constexpr lib part 1/3
  2019-07-31 15:00       ` Ed Smith-Rowland via gcc-patches
@ 2019-08-01 10:56         ` Jonathan Wakely
  2019-08-01 15:47           ` Ed Smith-Rowland via gcc-patches
  0 siblings, 1 reply; 22+ messages in thread
From: Jonathan Wakely @ 2019-08-01 10:56 UTC (permalink / raw)
  To: Ed Smith-Rowland; +Cc: Ville Voutilainen, libstdc++, gcc-patches

On 31/07/19 10:50 -0400, Ed Smith-Rowland via libstdc++ wrote:
>Here is the patch for
>
>* Implement C++20 p0202 - Add constexpr Modifiers to Functions in 
><algorithm> and <utility> Headers.
>
>* Implement C++20 p1023 - constexpr comparison operators for std::array.
>
>Relative to the last effort it is rebased on more recent trunk and I 
>added to <version>.
>
>There's some chance that I'll have to tweak the macros after the draft 
>comes in but I'd like to get this moving.?? I've got other chunks of 
>constexpr lib coming.?? This passes C++20 testing onx86_64-linux.
>
>Ok?

Calls to the new __memmove and __memcmp functions need to be qualified
with std:: to prevent ADL. I think we should rename those functions,
but that can happen later.

The new 23_containers/array/comparison_operators/constexpr.cc test
will be UNSUPPORTED by default because it doesn't have the directive
{ dg-options "-std=gnu++2a" }.

The change to the <version> header defines __cpp_lib_constexpr instead
of __cpp_lib_constexpr_algorithms as it should be. For some recent
changes I've added a testcase that does nothing but include <version>
and check the feature test macro, which ensures that it's set
correctly by <version> not just by the other header(s) defining it.
For example, see testsuite/26_numerics/numbers/2.cc added yesterday.

I wonder if the feature test macro should only be defined when
__cpp_lib_is_constant_evaluated is defined, because otherwise some
algos will not be usable constant expressions (e.g. when compiled with
Clang 7.0).

OK for trunk with:

- std:: qualification on the new __mem* functions;
- the dg-options added to the testcase;
- fix the macro in <version> (and ideally add a test for it).

Thanks.

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH 1/3] C++20 constexpr lib part 1/3
  2019-08-01 10:56         ` Jonathan Wakely
@ 2019-08-01 15:47           ` Ed Smith-Rowland via gcc-patches
  2019-08-01 17:16             ` [PATCH 2/3] C++20 constexpr lib part 2/3 - swappish functions Ed Smith-Rowland via gcc-patches
  2019-08-01 19:45             ` [PATCH 1/3] C++20 constexpr lib part 1/3 Jonathan Wakely
  0 siblings, 2 replies; 22+ messages in thread
From: Ed Smith-Rowland via gcc-patches @ 2019-08-01 15:47 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: Ville Voutilainen, libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 2208 bytes --]

On 8/1/19 6:56 AM, Jonathan Wakely wrote:
> On 31/07/19 10:50 -0400, Ed Smith-Rowland via libstdc++ wrote:
>> Here is the patch for
>>
>> * Implement C++20 p0202 - Add constexpr Modifiers to Functions in 
>> <algorithm> and <utility> Headers.
>>
>> * Implement C++20 p1023 - constexpr comparison operators for std::array.
>>
>> Relative to the last effort it is rebased on more recent trunk and I 
>> added to <version>.
>>
>> There's some chance that I'll have to tweak the macros after the 
>> draft comes in but I'd like to get this moving.?? I've got other 
>> chunks of constexpr lib coming.?? This passes C++20 testing 
>> onx86_64-linux.
>>
>> Ok?
>
> Calls to the new __memmove and __memcmp functions need to be qualified
> with std:: to prevent ADL. I think we should rename those functions,
> but that can happen later.

IMHO, these concepts are too important to leave as an implementation detail.

I suspect the committee will come crawling back to specify these with 
real names.

memory_copy, memory_compare, memory_move for C++23 anyone?

> The new 23_containers/array/comparison_operators/constexpr.cc test
> will be UNSUPPORTED by default because it doesn't have the directive
> { dg-options "-std=gnu++2a" }.
>
> The change to the <version> header defines __cpp_lib_constexpr instead
> of __cpp_lib_constexpr_algorithms as it should be. For some recent
> changes I've added a testcase that does nothing but include <version>
> and check the feature test macro, which ensures that it's set
> correctly by <version> not just by the other header(s) defining it.
> For example, see testsuite/26_numerics/numbers/2.cc added yesterday.
I'll add a testcase.
> I wonder if the feature test macro should only be defined when
> __cpp_lib_is_constant_evaluated is defined, because otherwise some
> algos will not be usable constant expressions (e.g. when compiled with
> Clang 7.0).
We can do this later if we need to.
>
> OK for trunk with:
>
> - std:: qualification on the new __mem* functions;
Done.
> - the dg-options added to the testcase;
Done.
> - fix the macro in <version> (and ideally add a test for it).
Done.
> Thanks.

Committed with 273975.?? Final patch and CL attached.

Regards,

Ed



[-- Attachment #2: CL_constexpr_lib --]
[-- Type: text/plain, Size: 7208 bytes --]

2019-08-01  Edward Smith-Rowland  <3dw4rd@verizon.net>

	Implement C++20 p0202 - Add Constexpr Modifiers to Functions
	in <algorithm> and <utility> Headers.
	Implement C++20 p1023 - constexpr comparison operators for std::array.
	* include/bits/algorithmfwd.h (all_of, any_of, binary_search, copy,
	copy_backward, copy_if, copy_n, equal_range, fill, find_end,
	find_if_not, includes, is_heap, is_heap_until, is_partitioned,
	is_permutation, is_sorted, is_sorted_until, iter_swap, lower_bound,
	none_of, partition_copy, partition_point, remove, remove_if,
	remove_copy, remove_copy_if, replace_copy, replace_copy_if,
	reverse_copy, rotate_copy, uunique, upper_bound, adjacent_find, count,
	count_if, equal, find, find_first_of, find_if, for_each, generate,
	generate_n, lexicographical_compare, merge, mismatch, replace,
	replace_if, search, search_n, set_difference, set_intersection,
	set_symmetric_difference, set_union, transform, unique_copy):
	Mark constexpr.
	* include/bits/cpp_type_traits.h (__miter_base): Mark constexpr.
	* include/bits/predefined_ops.h (_Iter_less_val::operator(),
	_Val_less_iter::operator(), _Iter_equal_to_iter::operator(),
	_Iter_equal_to_val::operator(), _Iter_equals_val::operator()):
	 Use const ref instead of ref arg;
	(_Iter_less_val, __iter_less_val, _Val_less_iter, __val_less_iter,
	__iter_equal_to_iter, __iter_equal_to_val, __iter_comp_val,
	_Iter_comp_val, _Val_comp_iter, __val_comp_iter, __iter_equals_val,
	_Iter_equals_iter, __iter_comp_iter, _Iter_pred, __pred_iter,
	_Iter_comp_to_val, __iter_comp_val, _Iter_comp_to_iter,
	__iter_comp_iter): Mark constexpr.
	* include/bits/stl_algo.h (__find_if, __find_if_not, __find_if_not_n,
	__search, __search_n_aux, __search_n, __find_end, find_end, all_of,
	none_of, any_of, find_if_not, is_partitioned, partition_point,
	__remove_copy_if, remove_copy, remove_copy_if, copy_if, __copy_n,
	copy_n, partition_copy, __remove_if, remove, remove_if, __adjacent_find,
	__unique, unique, __unique_copy, reverse_copy, rotate_copy,
	__unguarded_linear_insert, __insertion_sort, __unguarded_insertion_sort,
	__final_insertion_sort, lower_bound, __upper_bound, upper_bound,
	__equal_range, equal_range, binary_search, __includes, includes,
	__next_permutation, __prev_permutation, __replace_copy_if, replace_copy,
	replace_copy_if, __count_if, is_sorted, __is_sorted_until,
	is_sorted_until, __is_permutation, is_permutation, for_each, find,
	find_if, find_first_of, adjacent_find, count, count_if, search,
	search_n, transform, replace, replace_if, generate, generate_n,
	unique_copy, __merge, merge, __set_union, set_union, __set_intersection,
	set_intersection, __set_difference, set_difference,
	__set_symmetric_difference, set_symmetric_difference):  Mark constexpr.
	* include/bits/stl_algobase.h (__memmove, __memcmp): New maybe constexpr
	wrappers around __builtin_memmove and __builtin_memcmp
	respectively;
	(__niter_base, __niter_wrap, __copy_m, __copy_move_a, __copy_move_a2,
	copy, move, __copy_move_b, __copy_move_backward_a,
	__copy_move_backward_a2, copy_backward, move_backward, __fill_a, fill,
	__fill_n_a, fill_n, equal, __lc_rai::__newlast1, __lc_rai::__cnd2,
	__lexicographical_compare_impl, __lexicographical_compare,
	__lexicographical_compare<true>::__lc, __lexicographical_compare_aux,
	__lower_bound, lower_bound, equal, __equal4, lexicographical_compare,
	__mismatch, mismatch, __is_heap_until, __is_heap, is_heap_until,
	is_heap): Mark constexpr.
	* include/bits/stl_heap.h (__is_heap_until, __is_heap, is_heap_until,
	is_heap): Mark constexpr.
	* include/bits/stl_iterator.h (__niter_base, __miter_base): Mark constexpr.
	* include/std/array: Make comparison ops constexpr.
	* include/std/utility: Make exchange constexpr.
	* include/std/version (__cpp_lib_constexpr_algorithms): New macro.
	* testsuite/23_containers/array/tuple_interface/get_neg.cc: Adjust.
	* testsuite/23_containers/array/tuple_interface/
	tuple_element_neg.cc: Adjust.
	* testsuite/20_util/exchange/constexpr.cc: New.
	* testsuite/23_containers/array/comparison_operators/constexpr.cc: New.
	* testsuite/25_algorithms/constexpr_macro.cc: New.
	* testsuite/25_algorithms/adjacent_find/constexpr.cc: New.
	* testsuite/25_algorithms/all_of/constexpr.cc: New.
	* testsuite/25_algorithms/any_of/constexpr.cc: New.
	* testsuite/25_algorithms/binary_search/constexpr.cc: New.
	* testsuite/25_algorithms/copy/constexpr.cc: New.
	* testsuite/25_algorithms/copy_backward/constexpr.cc: New.
	* testsuite/25_algorithms/copy_if/constexpr.cc: New.
	* testsuite/25_algorithms/copy_n/constexpr.cc: New.
	* testsuite/25_algorithms/count/constexpr.cc: New.
	* testsuite/25_algorithms/count_if/constexpr.cc: New.
	* testsuite/25_algorithms/equal/constexpr.cc: New.
	* testsuite/25_algorithms/equal_range/constexpr.cc: New.
	* testsuite/25_algorithms/fill/constexpr.cc: New.
	* testsuite/25_algorithms/fill_n/constexpr.cc: New.
	* testsuite/25_algorithms/find/constexpr.cc: New.
	* testsuite/25_algorithms/find_end/constexpr.cc: New.
	* testsuite/25_algorithms/find_first_of/constexpr.cc: New.
	* testsuite/25_algorithms/find_if/constexpr.cc: New.
	* testsuite/25_algorithms/find_if_not/constexpr.cc: New.
	* testsuite/25_algorithms/for_each/constexpr.cc: New.
	* testsuite/25_algorithms/generate/constexpr.cc: New.
	* testsuite/25_algorithms/generate_n/constexpr.cc: New.
	* testsuite/25_algorithms/is_heap/constexpr.cc: New.
	* testsuite/25_algorithms/is_heap_until/constexpr.cc: New.
	* testsuite/25_algorithms/is_partitioned/constexpr.cc: New.
	* testsuite/25_algorithms/is_permutation/constexpr.cc: New.
	* testsuite/25_algorithms/is_sorted/constexpr.cc: New.
	* testsuite/25_algorithms/is_sorted_until/constexpr.cc: New.
	* testsuite/25_algorithms/lexicographical_compare/constexpr.cc: New.
	* testsuite/25_algorithms/lower_bound/constexpr.cc: New.
	* testsuite/25_algorithms/merge/constexpr.cc: New.
	* testsuite/25_algorithms/mismatch/constexpr.cc: New.
	* testsuite/25_algorithms/none_of/constexpr.cc: New.
	* testsuite/25_algorithms/partition_copy/constexpr.cc: New.
	* testsuite/25_algorithms/partition_point/constexpr.cc: New.
	* testsuite/25_algorithms/remove/constexpr.cc: New.
	* testsuite/25_algorithms/remove_copy/constexpr.cc: New.
	* testsuite/25_algorithms/remove_copy_if/constexpr.cc: New.
	* testsuite/25_algorithms/remove_if/constexpr.cc: New.
	* testsuite/25_algorithms/replace_copy/constexpr.cc: New.
	* testsuite/25_algorithms/replace_copy_if/constexpr.cc: New.
	* testsuite/25_algorithms/replace_if/constexpr.cc: New.
	* testsuite/25_algorithms/reverse_copy/constexpr.cc: New.
	* testsuite/25_algorithms/rotate_copy/constexpr.cc: New.
	* testsuite/25_algorithms/search/constexpr.cc: New.
	* testsuite/25_algorithms/search_n/constexpr.cc: New.
	* testsuite/25_algorithms/set_difference/constexpr.cc: New.
	* testsuite/25_algorithms/set_intersection/constexpr.cc: New.
	* testsuite/25_algorithms/set_symmetric_difference/constexpr.cc: New.
	* testsuite/25_algorithms/set_union/constexpr.cc: New.
	* testsuite/25_algorithms/transform/constexpr.cc: New.
	* testsuite/25_algorithms/unique/constexpr.cc: New.
	* testsuite/25_algorithms/unique_copy/constexpr.cc: New.
	* testsuite/25_algorithms/upper_bound/constexpr.cc: New.

[-- Attachment #3: patch_constexpr_lib_4.bz2 --]
[-- Type: application/x-bzip, Size: 15133 bytes --]

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [PATCH 2/3] C++20 constexpr lib part 2/3 - swappish functions.
  2019-08-01 15:47           ` Ed Smith-Rowland via gcc-patches
@ 2019-08-01 17:16             ` Ed Smith-Rowland via gcc-patches
  2019-08-13 11:24               ` Jonathan Wakely
  2019-08-01 19:45             ` [PATCH 1/3] C++20 constexpr lib part 1/3 Jonathan Wakely
  1 sibling, 1 reply; 22+ messages in thread
From: Ed Smith-Rowland via gcc-patches @ 2019-08-01 17:16 UTC (permalink / raw)
  To: Jonathan Wakely, libstdc++; +Cc: Ville Voutilainen, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 249 bytes --]

Greetings,

Here is a patch for C++20 p0879 - Constexpr for swap and swap related 
functions.

This essentially constexprifies the rest of <algorithm>.

Built and tested with C++20 (and pre-c++20) on x86_64-linux.

Ok?

Regards,

Ed Smith-Rowland



[-- Attachment #2: CL_constexpr_swap --]
[-- Type: text/plain, Size: 2266 bytes --]

2019-08-01  Edward Smith-Rowland  <3dw4rd@verizon.net>

	Implement C++20 p0879 - Constexpr for swap and swap related functions.
	* include/bits/algorithmfwd.h (__cpp_lib_constexpr_swap_algorithms):
	New macro. (iter_swap, make_heap, next_permutation, partial_sort_copy,
	pop_heap, prev_permutation, push_heap, reverse, rotate, sort_heap,
	swap, swap_ranges, nth_element, partial_sort, sort): Add constexpr.
	* include/bits/move.h (swap): Add constexpr.
	* include/bits/stl_algo.h (__move_median_to_first, __reverse, reverse,
	__gcd, __rotate, rotate, __partition, __heap_select,
	__partial_sort_copy, partial_sort_copy, __unguarded_partition,
	__unguarded_partition_pivot, __partial_sort, __introsort_loop, __sort,
	__introselect, __chunk_insertion_sort, next_permutation,
	prev_permutation, partition, partial_sort, nth_element, sort,
	__iter_swap::iter_swap, iter_swap, swap_ranges): Add constexpr.
	* include/bits/stl_algobase.h (__iter_swap::iter_swap, iter_swap,
	swap_ranges): Add constexpr.
	* include/bits/stl_heap.h (__push_heap, push_heap, __adjust_heap,
	__pop_heap, pop_heap, __make_heap, make_heap, __sort_heap, sort_heap):
	Add constexpr.
	* include/std/type_traits (swap): Add constexpr.
	* testsuite/25_algorithms/headers/algorithm/synopsis.cc: Add constexpr.
	* testsuite/25_algorithms/iter_swap/constexpr.cc: New test.
	* testsuite/25_algorithms/make_heap/constexpr.cc: New test.
	* testsuite/25_algorithms/next_permutation/constexpr.cc: New test.
	* testsuite/25_algorithms/nth_element/constexpr.cc: New test.
	* testsuite/25_algorithms/partial_sort/constexpr.cc: New test.
	* testsuite/25_algorithms/partial_sort_copy/constexpr.cc: New test.
	* testsuite/25_algorithms/partition/constexpr.cc: New test.
	* testsuite/25_algorithms/pop_heap/constexpr.cc: New test.
	* testsuite/25_algorithms/prev_permutation/constexpr.cc: New test.
	* testsuite/25_algorithms/push_heap/constexpr.cc: New test.
	* testsuite/25_algorithms/reverse/constexpr.cc: New test.
	* testsuite/25_algorithms/rotate/constexpr.cc: New test.
	* testsuite/25_algorithms/sort/constexpr.cc: New test.
	* testsuite/25_algorithms/sort_heap/constexpr.cc: New test.
	* testsuite/25_algorithms/swap/constexpr.cc: New test.
	* testsuite/25_algorithms/swap_ranges/constexpr.cc: New test.


[-- Attachment #3: patch_constexpr_swap --]
[-- Type: text/plain, Size: 54903 bytes --]

diff --git a/libstdc++-v3/include/bits/algorithmfwd.h b/libstdc++-v3/include/bits/algorithmfwd.h
index 99491db1c5e..24b6849e53e 100644
--- a/libstdc++-v3/include/bits/algorithmfwd.h
+++ b/libstdc++-v3/include/bits/algorithmfwd.h
@@ -193,6 +193,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
 #if __cplusplus > 201703L
 #  define __cpp_lib_constexpr_algorithms 201711L
+#  define __cpp_lib_constexpr_swap_algorithms 201712L
 #endif
 
 #if __cplusplus >= 201103L
@@ -377,6 +378,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 #endif
 
   template<typename _FIter1, typename _FIter2>
+    _GLIBCXX20_CONSTEXPR
     void
     iter_swap(_FIter1, _FIter2);
 
@@ -391,10 +393,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     lower_bound(_FIter, _FIter, const _Tp&, _Compare);
 
   template<typename _RAIter>
+    _GLIBCXX20_CONSTEXPR
     void
     make_heap(_RAIter, _RAIter);
 
   template<typename _RAIter, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     void
     make_heap(_RAIter, _RAIter, _Compare);
 
@@ -478,10 +482,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   // mismatch
 
   template<typename _BIter>
+    _GLIBCXX20_CONSTEXPR
     bool
     next_permutation(_BIter, _BIter);
 
   template<typename _BIter, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     bool
     next_permutation(_BIter, _BIter, _Compare);
 
@@ -496,10 +502,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   // partial_sort
 
   template<typename _IIter, typename _RAIter>
+    _GLIBCXX20_CONSTEXPR
     _RAIter
     partial_sort_copy(_IIter, _IIter, _RAIter, _RAIter);
 
   template<typename _IIter, typename _RAIter, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     _RAIter
     partial_sort_copy(_IIter, _IIter, _RAIter, _RAIter, _Compare);
 
@@ -519,26 +527,32 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 #endif
 
   template<typename _RAIter>
+    _GLIBCXX20_CONSTEXPR
     void
     pop_heap(_RAIter, _RAIter);
 
   template<typename _RAIter, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     void
     pop_heap(_RAIter, _RAIter, _Compare);
 
   template<typename _BIter>
+    _GLIBCXX20_CONSTEXPR
     bool
     prev_permutation(_BIter, _BIter);
 
   template<typename _BIter, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     bool
     prev_permutation(_BIter, _BIter, _Compare);
 
   template<typename _RAIter>
+    _GLIBCXX20_CONSTEXPR
     void
     push_heap(_RAIter, _RAIter);
 
   template<typename _RAIter, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     void
     push_heap(_RAIter, _RAIter, _Compare);
 
@@ -579,6 +593,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   // replace_if
 
   template<typename _BIter>
+    _GLIBCXX20_CONSTEXPR
     void
     reverse(_BIter, _BIter);
 
@@ -590,6 +605,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   inline namespace _V2
   {
     template<typename _FIter>
+      _GLIBCXX20_CONSTEXPR
       _FIter
       rotate(_FIter, _FIter, _FIter);
   }
@@ -613,10 +629,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 #endif
 
   template<typename _RAIter>
+    _GLIBCXX20_CONSTEXPR
     void
     sort_heap(_RAIter, _RAIter);
 
   template<typename _RAIter, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     void
     sort_heap(_RAIter, _RAIter, _Compare);
 
@@ -628,15 +646,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   // For C++11 swap() is declared in <type_traits>.
 
   template<typename _Tp, size_t _Nm>
+    _GLIBCXX20_CONSTEXPR
     inline void
     swap(_Tp& __a, _Tp& __b);
 
   template<typename _Tp, size_t _Nm>
+    _GLIBCXX20_CONSTEXPR
     inline void
     swap(_Tp (&__a)[_Nm], _Tp (&__b)[_Nm]);
 #endif
 
   template<typename _FIter1, typename _FIter2>
+    _GLIBCXX20_CONSTEXPR
     _FIter2
     swap_ranges(_FIter1, _FIter1, _FIter2);
 
@@ -783,22 +804,27 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO
     mismatch(_IIter1, _IIter1, _IIter2, _BinaryPredicate);
 
   template<typename _RAIter>
+    _GLIBCXX20_CONSTEXPR
     void
     nth_element(_RAIter, _RAIter, _RAIter);
 
   template<typename _RAIter, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     void
     nth_element(_RAIter, _RAIter, _RAIter, _Compare);
 
   template<typename _RAIter>
+    _GLIBCXX20_CONSTEXPR
     void
     partial_sort(_RAIter, _RAIter, _RAIter);
 
   template<typename _RAIter, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     void
     partial_sort(_RAIter, _RAIter, _RAIter, _Compare);
 
   template<typename _BIter, typename _Predicate>
+    _GLIBCXX20_CONSTEXPR
     _BIter
     partition(_BIter, _BIter, _Predicate);
 
@@ -892,10 +918,12 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO
     set_union(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, _Compare);
 
   template<typename _RAIter>
+    _GLIBCXX20_CONSTEXPR
     void
     sort(_RAIter, _RAIter);
 
   template<typename _RAIter, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     void
     sort(_RAIter, _RAIter, _Compare);
 
diff --git a/libstdc++-v3/include/bits/move.h b/libstdc++-v3/include/bits/move.h
index e3ddeb563b4..d7c7068e29c 100644
--- a/libstdc++-v3/include/bits/move.h
+++ b/libstdc++-v3/include/bits/move.h
@@ -175,6 +175,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
    *  @return   Nothing.
   */
   template<typename _Tp>
+    _GLIBCXX20_CONSTEXPR
     inline
 #if __cplusplus >= 201103L
     typename enable_if<__and_<__not_<__is_tuple_like<_Tp>>,
@@ -199,6 +200,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   // DR 809. std::swap should be overloaded for array types.
   /// Swap the contents of two arrays.
   template<typename _Tp, size_t _Nm>
+    _GLIBCXX20_CONSTEXPR
     inline
 #if __cplusplus >= 201103L
     typename enable_if<__is_swappable<_Tp>::value>::type
diff --git a/libstdc++-v3/include/bits/stl_algo.h b/libstdc++-v3/include/bits/stl_algo.h
index 0d707250d2e..bece93379de 100644
--- a/libstdc++-v3/include/bits/stl_algo.h
+++ b/libstdc++-v3/include/bits/stl_algo.h
@@ -74,6 +74,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   /// Swaps the median value of *__a, *__b and *__c under __comp to *__result
   template<typename _Iterator, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     void
     __move_median_to_first(_Iterator __result,_Iterator __a, _Iterator __b,
 			   _Iterator __c, _Compare __comp)
@@ -1162,6 +1163,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
    *  overloaded for bidirectional iterators.
   */
   template<typename _BidirectionalIterator>
+    _GLIBCXX20_CONSTEXPR
     void
     __reverse(_BidirectionalIterator __first, _BidirectionalIterator __last,
 	      bidirectional_iterator_tag)
@@ -1182,6 +1184,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
    *  overloaded for random access iterators.
   */
   template<typename _RandomAccessIterator>
+    _GLIBCXX20_CONSTEXPR
     void
     __reverse(_RandomAccessIterator __first, _RandomAccessIterator __last,
 	      random_access_iterator_tag)
@@ -1210,6 +1213,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
    *  swaps @p *(__first+i) and @p *(__last-(i+1))
   */
   template<typename _BidirectionalIterator>
+    _GLIBCXX20_CONSTEXPR
     inline void
     reverse(_BidirectionalIterator __first, _BidirectionalIterator __last)
     {
@@ -1263,6 +1267,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
    *  It returns the greatest common divisor of two integer values.
   */
   template<typename _EuclideanRingElement>
+    _GLIBCXX20_CONSTEXPR
     _EuclideanRingElement
     __gcd(_EuclideanRingElement __m, _EuclideanRingElement __n)
     {
@@ -1280,6 +1285,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   /// This is a helper function for the rotate algorithm.
   template<typename _ForwardIterator>
+    _GLIBCXX20_CONSTEXPR
     _ForwardIterator
     __rotate(_ForwardIterator __first,
 	     _ForwardIterator __middle,
@@ -1321,6 +1327,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
    /// This is a helper function for the rotate algorithm.
   template<typename _BidirectionalIterator>
+    _GLIBCXX20_CONSTEXPR
     _BidirectionalIterator
     __rotate(_BidirectionalIterator __first,
 	     _BidirectionalIterator __middle,
@@ -1359,6 +1366,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   /// This is a helper function for the rotate algorithm.
   template<typename _RandomAccessIterator>
+    _GLIBCXX20_CONSTEXPR
     _RandomAccessIterator
     __rotate(_RandomAccessIterator __first,
 	     _RandomAccessIterator __middle,
@@ -1465,6 +1473,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
    *  for each @p n in the range @p [0,__last-__first).
   */
   template<typename _ForwardIterator>
+    _GLIBCXX20_CONSTEXPR
     inline _ForwardIterator
     rotate(_ForwardIterator __first, _ForwardIterator __middle,
 	   _ForwardIterator __last)
@@ -1520,6 +1529,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   /// This is a helper function...
   template<typename _ForwardIterator, typename _Predicate>
+    _GLIBCXX20_CONSTEXPR
     _ForwardIterator
     __partition(_ForwardIterator __first, _ForwardIterator __last,
 		_Predicate __pred, forward_iterator_tag)
@@ -1545,6 +1555,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   /// This is a helper function...
   template<typename _BidirectionalIterator, typename _Predicate>
+    _GLIBCXX20_CONSTEXPR
     _BidirectionalIterator
     __partition(_BidirectionalIterator __first, _BidirectionalIterator __last,
 		_Predicate __pred, bidirectional_iterator_tag)
@@ -1699,6 +1710,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   /// This is a helper function for the sort routines.
   template<typename _RandomAccessIterator, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     void
     __heap_select(_RandomAccessIterator __first,
 		  _RandomAccessIterator __middle,
@@ -1714,6 +1726,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   template<typename _InputIterator, typename _RandomAccessIterator,
 	   typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     _RandomAccessIterator
     __partial_sort_copy(_InputIterator __first, _InputIterator __last,
 			_RandomAccessIterator __result_first,
@@ -1768,6 +1781,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
    *  The value returned is @p __result_first+N.
   */
   template<typename _InputIterator, typename _RandomAccessIterator>
+    _GLIBCXX20_CONSTEXPR
     inline _RandomAccessIterator
     partial_sort_copy(_InputIterator __first, _InputIterator __last,
 		      _RandomAccessIterator __result_first,
@@ -1818,6 +1832,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   */
   template<typename _InputIterator, typename _RandomAccessIterator,
 	   typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     inline _RandomAccessIterator
     partial_sort_copy(_InputIterator __first, _InputIterator __last,
 		      _RandomAccessIterator __result_first,
@@ -1931,6 +1946,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   /// This is a helper function...
   template<typename _RandomAccessIterator, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     _RandomAccessIterator
     __unguarded_partition(_RandomAccessIterator __first,
 			  _RandomAccessIterator __last,
@@ -1952,6 +1968,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   /// This is a helper function...
   template<typename _RandomAccessIterator, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     inline _RandomAccessIterator
     __unguarded_partition_pivot(_RandomAccessIterator __first,
 				_RandomAccessIterator __last, _Compare __comp)
@@ -1963,6 +1980,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     }
 
   template<typename _RandomAccessIterator, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     inline void
     __partial_sort(_RandomAccessIterator __first,
 		   _RandomAccessIterator __middle,
@@ -1975,6 +1993,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   /// This is a helper function for the sort routine.
   template<typename _RandomAccessIterator, typename _Size, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     void
     __introsort_loop(_RandomAccessIterator __first,
 		     _RandomAccessIterator __last,
@@ -1998,6 +2017,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   // sort
 
   template<typename _RandomAccessIterator, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     inline void
     __sort(_RandomAccessIterator __first, _RandomAccessIterator __last,
 	   _Compare __comp)
@@ -2012,6 +2032,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     }
 
   template<typename _RandomAccessIterator, typename _Size, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     void
     __introselect(_RandomAccessIterator __first, _RandomAccessIterator __nth,
 		  _RandomAccessIterator __last, _Size __depth_limit,
@@ -2728,6 +2749,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   template<typename _RandomAccessIterator, typename _Distance,
 	   typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     void
     __chunk_insertion_sort(_RandomAccessIterator __first,
 			   _RandomAccessIterator __last,
@@ -2997,6 +3019,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
    *  is the largest of the set, the smallest is generated and false returned.
   */
   template<typename _BidirectionalIterator>
+    _GLIBCXX20_CONSTEXPR
     inline bool
     next_permutation(_BidirectionalIterator __first,
 		     _BidirectionalIterator __last)
@@ -3029,6 +3052,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
    *  smallest is generated and false returned.
   */
   template<typename _BidirectionalIterator, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     inline bool
     next_permutation(_BidirectionalIterator __first,
 		     _BidirectionalIterator __last, _Compare __comp)
@@ -3098,6 +3122,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
    *  returned.
   */
   template<typename _BidirectionalIterator>
+    _GLIBCXX20_CONSTEXPR
     inline bool
     prev_permutation(_BidirectionalIterator __first,
 		     _BidirectionalIterator __last)
@@ -3130,6 +3155,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
    *  the largest is generated and false returned.
   */
   template<typename _BidirectionalIterator, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     inline bool
     prev_permutation(_BidirectionalIterator __first,
 		     _BidirectionalIterator __last, _Compare __comp)
@@ -4757,6 +4783,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO
    *  @p stable_partition() if this is needed.
   */
   template<typename _ForwardIterator, typename _Predicate>
+    _GLIBCXX20_CONSTEXPR
     inline _ForwardIterator
     partition(_ForwardIterator __first, _ForwardIterator __last,
 	      _Predicate   __pred)
@@ -4790,6 +4817,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO
    *  the range @p [__middle,__last) then *j<*i and *k<*i are both false.
   */
   template<typename _RandomAccessIterator>
+    _GLIBCXX20_CONSTEXPR
     inline void
     partial_sort(_RandomAccessIterator __first,
 		 _RandomAccessIterator __middle,
@@ -4828,6 +4856,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO
    *  are both false.
   */
   template<typename _RandomAccessIterator, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     inline void
     partial_sort(_RandomAccessIterator __first,
 		 _RandomAccessIterator __middle,
@@ -4864,6 +4893,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO
    *  holds that *j < *i is false.
   */
   template<typename _RandomAccessIterator>
+    _GLIBCXX20_CONSTEXPR
     inline void
     nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth,
 		_RandomAccessIterator __last)
@@ -4903,6 +4933,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO
    *  holds that @p __comp(*j,*i) is false.
   */
   template<typename _RandomAccessIterator, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     inline void
     nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth,
 		_RandomAccessIterator __last, _Compare __comp)
@@ -4940,6 +4971,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO
    *  @p stable_sort() if this is needed.
   */
   template<typename _RandomAccessIterator>
+    _GLIBCXX20_CONSTEXPR
     inline void
     sort(_RandomAccessIterator __first, _RandomAccessIterator __last)
     {
@@ -4970,6 +5002,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO
    *  @p stable_sort() if this is needed.
   */
   template<typename _RandomAccessIterator, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     inline void
     sort(_RandomAccessIterator __first, _RandomAccessIterator __last,
 	 _Compare __comp)
diff --git a/libstdc++-v3/include/bits/stl_algobase.h b/libstdc++-v3/include/bits/stl_algobase.h
index ab1ff5185d4..36bb9ccb777 100644
--- a/libstdc++-v3/include/bits/stl_algobase.h
+++ b/libstdc++-v3/include/bits/stl_algobase.h
@@ -136,6 +136,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     struct __iter_swap
     {
       template<typename _ForwardIterator1, typename _ForwardIterator2>
+	_GLIBCXX20_CONSTEXPR
 	static void
 	iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
 	{
@@ -151,6 +152,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     struct __iter_swap<true>
     {
       template<typename _ForwardIterator1, typename _ForwardIterator2>
+	_GLIBCXX20_CONSTEXPR
 	static void
 	iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
 	{
@@ -170,6 +172,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
    *  iterators themselves.
   */
   template<typename _ForwardIterator1, typename _ForwardIterator2>
+    _GLIBCXX20_CONSTEXPR
     inline void
     iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
     {
@@ -216,6 +219,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
    *  The ranges must not overlap.
   */
   template<typename _ForwardIterator1, typename _ForwardIterator2>
+    _GLIBCXX20_CONSTEXPR
     _ForwardIterator2
     swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
 		_ForwardIterator2 __first2)
diff --git a/libstdc++-v3/include/bits/stl_heap.h b/libstdc++-v3/include/bits/stl_heap.h
index d9530e66621..7eb12f04321 100644
--- a/libstdc++-v3/include/bits/stl_heap.h
+++ b/libstdc++-v3/include/bits/stl_heap.h
@@ -129,6 +129,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   template<typename _RandomAccessIterator, typename _Distance, typename _Tp,
 	   typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     void
     __push_heap(_RandomAccessIterator __first,
 		_Distance __holeIndex, _Distance __topIndex, _Tp __value,
@@ -155,6 +156,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
    *  [__first,__last) is a valid heap.
   */
   template<typename _RandomAccessIterator>
+    _GLIBCXX20_CONSTEXPR
     inline void
     push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
     {
@@ -190,6 +192,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
    *  performed using comp.
   */
   template<typename _RandomAccessIterator, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     inline void
     push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last,
 	      _Compare __comp)
@@ -215,6 +218,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   template<typename _RandomAccessIterator, typename _Distance,
 	   typename _Tp, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     void
     __adjust_heap(_RandomAccessIterator __first, _Distance __holeIndex,
 		  _Distance __len, _Tp __value, _Compare __comp)
@@ -244,6 +248,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     }
 
   template<typename _RandomAccessIterator, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     inline void
     __pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last,
 	       _RandomAccessIterator __result, _Compare& __comp)
@@ -272,6 +277,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
    *  heap.
   */
   template<typename _RandomAccessIterator>
+    _GLIBCXX20_CONSTEXPR
     inline void
     pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
     {
@@ -305,6 +311,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
    *  heap.  Comparisons are made using comp.
   */
   template<typename _RandomAccessIterator, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     inline void
     pop_heap(_RandomAccessIterator __first,
 	     _RandomAccessIterator __last, _Compare __comp)
@@ -327,6 +334,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     }
 
   template<typename _RandomAccessIterator, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     void
     __make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last,
 		_Compare& __comp)
@@ -361,6 +369,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
    *  This operation makes the elements in [__first,__last) into a heap.
   */
   template<typename _RandomAccessIterator>
+    _GLIBCXX20_CONSTEXPR
     inline void
     make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
     {
@@ -387,6 +396,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
    *  Comparisons are made using __comp.
   */
   template<typename _RandomAccessIterator, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     inline void
     make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last,
 	      _Compare __comp)
@@ -403,6 +413,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     }
 
   template<typename _RandomAccessIterator, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     void
     __sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last,
 		_Compare& __comp)
@@ -423,6 +434,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
    *  This operation sorts the valid heap in the range [__first,__last).
   */
   template<typename _RandomAccessIterator>
+    _GLIBCXX20_CONSTEXPR
     inline void
     sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
     {
@@ -450,6 +462,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
    *  Comparisons are made using __comp.
   */
   template<typename _RandomAccessIterator, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     inline void
     sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last,
 	      _Compare __comp)
diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits
index 9428dadc9d7..b31c26ab381 100644
--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -2695,6 +2695,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     { };
 
   template<typename _Tp>
+    _GLIBCXX20_CONSTEXPR
     inline
     typename enable_if<__and_<__not_<__is_tuple_like<_Tp>>,
 			      is_move_constructible<_Tp>,
@@ -2704,6 +2705,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	            is_nothrow_move_assignable<_Tp>>::value);
 
   template<typename _Tp, size_t _Nm>
+    _GLIBCXX20_CONSTEXPR
     inline
     typename enable_if<__is_swappable<_Tp>::value>::type
     swap(_Tp (&__a)[_Nm], _Tp (&__b)[_Nm])
diff --git a/libstdc++-v3/testsuite/25_algorithms/headers/algorithm/synopsis.cc b/libstdc++-v3/testsuite/25_algorithms/headers/algorithm/synopsis.cc
index d3b3540deb4..07dd7fbfac1 100644
--- a/libstdc++-v3/testsuite/25_algorithms/headers/algorithm/synopsis.cc
+++ b/libstdc++-v3/testsuite/25_algorithms/headers/algorithm/synopsis.cc
@@ -165,10 +165,12 @@ namespace std
   // 25.2.2, swap:
 #if __cplusplus < 201103L
   template<typename _Tp> 
+    _GLIBCXX20_CONSTEXPR
     void 
     swap(_Tp&, _Tp& b);
 
   template<typename _Tp, size_t _Nm>
+    _GLIBCXX20_CONSTEXPR
     void
     swap(_Tp (&)[_Nm], _Tp (&)[_Nm]);
 #else
@@ -178,10 +180,12 @@ namespace std
 #endif
 
   template<typename _FIter1, typename _FIter2>
+    _GLIBCXX20_CONSTEXPR
     _FIter2 
     swap_ranges(_FIter1 first1, _FIter1, _FIter2);
 
   template<typename _FIter1, typename _FIter2>
+    _GLIBCXX20_CONSTEXPR
     void 
     iter_swap(_FIter1, _FIter2 b);
 
@@ -295,6 +299,7 @@ namespace std
     unique_copy(_IIter, _IIter, _OIter, _BinaryPredicate);
 
   template<typename _BIter>
+    _GLIBCXX20_CONSTEXPR
     void 
     reverse(_BIter, _BIter);
 
@@ -304,6 +309,7 @@ namespace std
     reverse_copy(_BIter, _BIter, _OIter);
 
   template<typename _FIter>
+    _GLIBCXX20_CONSTEXPR
     void 
     rotate(_FIter, _FIter, _FIter);
 
@@ -322,6 +328,7 @@ namespace std
 
   // 25.2.12, partitions:
   template<typename _BIter, typename _Predicate>
+    _GLIBCXX20_CONSTEXPR
     _BIter 
     partition(_BIter, _BIter, _Predicate);
 
@@ -332,10 +339,12 @@ namespace std
   // 25.3, sorting and related operations:
   // 25.3.1, sorting:
   template<typename _RAIter>
+    _GLIBCXX20_CONSTEXPR
     void 
     sort(_RAIter, _RAIter);
 
   template<typename _RAIter, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     void 
     sort(_RAIter, _RAIter, _Compare);
 
@@ -348,26 +357,32 @@ namespace std
     stable_sort(_RAIter, _RAIter, _Compare);
 
   template<typename _RAIter>
+    _GLIBCXX20_CONSTEXPR
     void 
     partial_sort(_RAIter, _RAIter, _RAIter);
 
   template<typename _RAIter, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     void 
     partial_sort(_RAIter, _RAIter, _RAIter, _Compare);
 
   template<typename _IIter, typename _RAIter>
+    _GLIBCXX20_CONSTEXPR
     _RAIter
     partial_sort_copy(_IIter, _IIter, _RAIter, _RAIter);
 
   template<typename _IIter, typename _RAIter, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     _RAIter
     partial_sort_copy(_IIter, _IIter, _RAIter, _RAIter, _Compare);
 
   template<typename _RAIter>
+    _GLIBCXX20_CONSTEXPR
     void 
     nth_element(_RAIter, _RAIter, _RAIter);
 
   template<typename _RAIter, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     void 
     nth_element(_RAIter, _RAIter, _RAIter, _Compare);
 
@@ -490,34 +505,42 @@ namespace std
 
   // 25.3.6, heap operations:
   template<typename _RAIter>
+    _GLIBCXX20_CONSTEXPR
     void 
     push_heap(_RAIter, _RAIter);
 
   template<typename _RAIter, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     void 
     push_heap(_RAIter, _RAIter, _Compare);
 
   template<typename _RAIter>
+    _GLIBCXX20_CONSTEXPR
     void 
     pop_heap(_RAIter, _RAIter);
 
   template<typename _RAIter, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     void 
     pop_heap(_RAIter, _RAIter, _Compare);
 
   template<typename _RAIter>
+    _GLIBCXX20_CONSTEXPR
     void 
     make_heap(_RAIter, _RAIter);
 
   template<typename _RAIter, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     void 
     make_heap(_RAIter, _RAIter, _Compare);
 
   template<typename _RAIter>
+    _GLIBCXX20_CONSTEXPR
     void 
     sort_heap(_RAIter, _RAIter);
 
   template<typename _RAIter, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     void 
     sort_heap(_RAIter, _RAIter, _Compare);
 
@@ -668,18 +691,22 @@ namespace std
 
   // 25.3.9, permutations
   template<typename _BIter>
+    _GLIBCXX20_CONSTEXPR
     bool 
     next_permutation(_BIter, _BIter);
 
   template<typename _BIter, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     bool 
     next_permutation(_BIter, _BIter, _Compare);
 
   template<typename _BIter>
+    _GLIBCXX20_CONSTEXPR
     bool 
     prev_permutation(_BIter, _BIter);
 
   template<typename _BIter, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     bool 
     prev_permutation(_BIter, _BIter, _Compare);
 }
diff --git a/libstdc++-v3/testsuite/25_algorithms/iter_swap/constexpr.cc b/libstdc++-v3/testsuite/25_algorithms/iter_swap/constexpr.cc
new file mode 100644
index 00000000000..f11271b7976
--- /dev/null
+++ b/libstdc++-v3/testsuite/25_algorithms/iter_swap/constexpr.cc
@@ -0,0 +1,42 @@
+// 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/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <algorithm>
+#include <array>
+
+#ifndef __cpp_lib_constexpr_swap_algorithms
+# error "Feature-test macro for constexpr swap algorithms missing"
+#elif __cpp_lib_constexpr_swap_algorithms < 201712L
+# error "Feature-test macro for constexpr swap algorithms has wrong value"
+#endif
+
+constexpr bool
+test()
+{
+  auto ok = true;
+
+  std::array<int, 12> ar0{{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}};
+
+  std::iter_swap(ar0.begin() + 2, ar0.begin() + 5);
+
+  return ok = ar0[2] == 5 && ar0[5] == 2;
+}
+
+static_assert(test());
diff --git a/libstdc++-v3/testsuite/25_algorithms/make_heap/constexpr.cc b/libstdc++-v3/testsuite/25_algorithms/make_heap/constexpr.cc
new file mode 100644
index 00000000000..1ce994ebf6a
--- /dev/null
+++ b/libstdc++-v3/testsuite/25_algorithms/make_heap/constexpr.cc
@@ -0,0 +1,47 @@
+// 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/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <algorithm>
+#include <array>
+
+#ifndef __cpp_lib_constexpr_swap_algorithms
+# error "Feature-test macro for constexpr swap algorithms missing"
+#elif __cpp_lib_constexpr_swap_algorithms < 201712L
+# error "Feature-test macro for constexpr swap algorithms has wrong value"
+#endif
+
+constexpr bool
+test()
+{
+  auto ok = true;
+
+  std::array<int, 23>
+  ah{{0,
+      1, 2,
+      3, 4, 5, 6,
+      7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22}};
+
+  std::make_heap(ah.begin(), ah.begin() + 17);
+  ok = ok && std::is_heap(ah.begin(), ah.begin() + 17);
+
+  return ok;
+}
+
+static_assert(test());
diff --git a/libstdc++-v3/testsuite/25_algorithms/next_permutation/constexpr.cc b/libstdc++-v3/testsuite/25_algorithms/next_permutation/constexpr.cc
new file mode 100644
index 00000000000..f463eddf934
--- /dev/null
+++ b/libstdc++-v3/testsuite/25_algorithms/next_permutation/constexpr.cc
@@ -0,0 +1,42 @@
+// 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/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <algorithm>
+#include <array>
+
+#ifndef __cpp_lib_constexpr_swap_algorithms
+# error "Feature-test macro for constexpr swap algorithms missing"
+#elif __cpp_lib_constexpr_swap_algorithms < 201712L
+# error "Feature-test macro for constexpr swap algorithms has wrong value"
+#endif
+
+constexpr bool
+test()
+{
+  auto ok = true;
+
+  std::array<int, 12> ar0{{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}};
+
+  std::next_permutation(ar0.begin(), ar0.end());
+
+  return ok = ar0[11] == 10 && ar0[10] == 11;
+}
+
+static_assert(test());
diff --git a/libstdc++-v3/testsuite/25_algorithms/nth_element/constexpr.cc b/libstdc++-v3/testsuite/25_algorithms/nth_element/constexpr.cc
new file mode 100644
index 00000000000..2e20836ad38
--- /dev/null
+++ b/libstdc++-v3/testsuite/25_algorithms/nth_element/constexpr.cc
@@ -0,0 +1,47 @@
+// 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/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <algorithm>
+#include <array>
+
+#ifndef __cpp_lib_constexpr_swap_algorithms
+# error "Feature-test macro for constexpr swap algorithms missing"
+#elif __cpp_lib_constexpr_swap_algorithms < 201712L
+# error "Feature-test macro for constexpr swap algorithms has wrong value"
+#endif
+
+constexpr bool
+test()
+{
+  auto ok = true;
+
+  std::array<int, 12> ar0{{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}};
+
+  std::nth_element(ar0.begin(), ar0.begin() + 5, ar0.end());
+  ok = ok && ar0[5] == 5;
+
+  std::sort(ar0.begin(), ar0.end(), std::greater<>());
+  std::nth_element(ar0.begin(), ar0.begin() + 5, ar0.end(), std::greater<>());
+  ok = ok && ar0[5] == 6;
+
+  return ok;
+}
+
+static_assert(test());
diff --git a/libstdc++-v3/testsuite/25_algorithms/partial_sort/constexpr.cc b/libstdc++-v3/testsuite/25_algorithms/partial_sort/constexpr.cc
new file mode 100644
index 00000000000..e7d215981c0
--- /dev/null
+++ b/libstdc++-v3/testsuite/25_algorithms/partial_sort/constexpr.cc
@@ -0,0 +1,46 @@
+// 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/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <algorithm>
+#include <array>
+
+#ifndef __cpp_lib_constexpr_swap_algorithms
+# error "Feature-test macro for constexpr swap algorithms missing"
+#elif __cpp_lib_constexpr_swap_algorithms < 201712L
+# error "Feature-test macro for constexpr swap algorithms has wrong value"
+#endif
+
+constexpr bool
+test()
+{
+  auto ok = true;
+
+  std::array<int, 12> ar0{{0, 1, 7, 8, 9, 2, 3, 4, 5, 6, 10, 11}};
+
+  std::partial_sort(ar0.begin(), ar0.begin() + 5, ar0.end());
+  ok = ok && ar0[0] == 0 && ar0[4] == 4;
+
+  std::partial_sort(ar0.begin(), ar0.begin() + 5, ar0.end(), std::greater<>());
+  ok = ok && ar0[0] == 11 && ar0[4] == 7;
+
+  return ok;
+}
+
+static_assert(test());
diff --git a/libstdc++-v3/testsuite/25_algorithms/partial_sort_copy/constexpr.cc b/libstdc++-v3/testsuite/25_algorithms/partial_sort_copy/constexpr.cc
new file mode 100644
index 00000000000..94e6d2037d0
--- /dev/null
+++ b/libstdc++-v3/testsuite/25_algorithms/partial_sort_copy/constexpr.cc
@@ -0,0 +1,47 @@
+// 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/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <algorithm>
+#include <array>
+
+#ifndef __cpp_lib_constexpr_swap_algorithms
+# error "Feature-test macro for constexpr swap algorithms missing"
+#elif __cpp_lib_constexpr_swap_algorithms < 201712L
+# error "Feature-test macro for constexpr swap algorithms has wrong value"
+#endif
+
+constexpr bool
+test()
+{
+  auto ok = true;
+
+  const std::array<int, 12> ar0{{0, 7, 8, 9, 1, 2, 5, 6, 10, 3, 4, 11}};
+  std::array<int, 12> or0{{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
+
+  std::partial_sort_copy(ar0.begin() + 5, ar0.begin() + 10,
+			 or0.begin(), or0.begin() + 5);
+
+  std::partial_sort_copy(ar0.begin() + 5, ar0.begin() + 10,
+			 or0.begin(), or0.begin() + 5, std::greater<>());
+
+  return ok;
+}
+
+static_assert(test());
diff --git a/libstdc++-v3/testsuite/25_algorithms/partition/constexpr.cc b/libstdc++-v3/testsuite/25_algorithms/partition/constexpr.cc
new file mode 100644
index 00000000000..7f525951420
--- /dev/null
+++ b/libstdc++-v3/testsuite/25_algorithms/partition/constexpr.cc
@@ -0,0 +1,44 @@
+// 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/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <algorithm>
+#include <array>
+
+#ifndef __cpp_lib_constexpr_swap_algorithms
+# error "Feature-test macro for constexpr swap algorithms missing"
+#elif __cpp_lib_constexpr_swap_algorithms < 201712L
+# error "Feature-test macro for constexpr swap algorithms has wrong value"
+#endif
+
+constexpr bool
+test()
+{
+  auto ok = true;
+
+  std::array<int, 12> ar0{{10, 0, 5, 1, 2, 6, 7, 8, 3, 4, 9, 11}};
+
+  auto iter1 = std::partition(ar0.begin(), ar0.end(),
+			      [](int i){ return i < 7; });
+  ok = ok && *iter1 == 8;
+
+  return ok;
+}
+
+static_assert(test());
diff --git a/libstdc++-v3/testsuite/25_algorithms/pop_heap/constexpr.cc b/libstdc++-v3/testsuite/25_algorithms/pop_heap/constexpr.cc
new file mode 100644
index 00000000000..d1e7f268626
--- /dev/null
+++ b/libstdc++-v3/testsuite/25_algorithms/pop_heap/constexpr.cc
@@ -0,0 +1,53 @@
+// 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/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <algorithm>
+#include <array>
+
+#ifndef __cpp_lib_constexpr_swap_algorithms
+# error "Feature-test macro for constexpr swap algorithms missing"
+#elif __cpp_lib_constexpr_swap_algorithms < 201712L
+# error "Feature-test macro for constexpr swap algorithms has wrong value"
+#endif
+
+constexpr bool
+test()
+{
+  auto ok = true;
+
+  std::array<int, 23>
+  ah{{0,
+      1, 2,
+      3, 4, 5, 6,
+      7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22}};
+
+  std::make_heap(ah.begin(), ah.end());
+  ok = ok && std::is_heap(ah.begin(), ah.end());
+
+  std::pop_heap(ah.begin(), ah.end());
+  std::pop_heap(ah.begin(), ah.end() - 1);
+  std::pop_heap(ah.begin(), ah.end() - 2);
+  ok = ok && std::is_heap(ah.begin(), ah.end() - 3)
+	  && !std::is_heap(ah.begin(), ah.end());
+
+  return ok;
+}
+
+static_assert(test());
diff --git a/libstdc++-v3/testsuite/25_algorithms/prev_permutation/constexpr.cc b/libstdc++-v3/testsuite/25_algorithms/prev_permutation/constexpr.cc
new file mode 100644
index 00000000000..55218e5bb73
--- /dev/null
+++ b/libstdc++-v3/testsuite/25_algorithms/prev_permutation/constexpr.cc
@@ -0,0 +1,42 @@
+// 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/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <algorithm>
+#include <array>
+
+#ifndef __cpp_lib_constexpr_swap_algorithms
+# error "Feature-test macro for constexpr swap algorithms missing"
+#elif __cpp_lib_constexpr_swap_algorithms < 201712L
+# error "Feature-test macro for constexpr swap algorithms has wrong value"
+#endif
+
+constexpr bool
+test()
+{
+  auto ok = true;
+
+  std::array<int, 12> ar0{{1, 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}};
+
+  std::prev_permutation(ar0.begin(), ar0.end());
+
+  return ok = ar0[0] == 0;
+}
+
+static_assert(test());
diff --git a/libstdc++-v3/testsuite/25_algorithms/push_heap/constexpr.cc b/libstdc++-v3/testsuite/25_algorithms/push_heap/constexpr.cc
new file mode 100644
index 00000000000..ceb14ba6f0a
--- /dev/null
+++ b/libstdc++-v3/testsuite/25_algorithms/push_heap/constexpr.cc
@@ -0,0 +1,52 @@
+// 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/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <algorithm>
+#include <array>
+
+#ifndef __cpp_lib_constexpr_swap_algorithms
+# error "Feature-test macro for constexpr swap algorithms missing"
+#elif __cpp_lib_constexpr_swap_algorithms < 201712L
+# error "Feature-test macro for constexpr swap algorithms has wrong value"
+#endif
+
+constexpr bool
+test()
+{
+  auto ok = true;
+
+  std::array<int, 23>
+  ah{{0,
+      1, 2,
+      3, 4, 5, 6,
+      7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22}};
+
+  std::make_heap(ah.begin(), ah.end() - 3);
+  ok = ok && std::is_heap(ah.begin(), ah.end() - 3);
+
+  std::push_heap(ah.begin(), ah.end() - 2);
+  std::push_heap(ah.begin(), ah.end() - 1);
+  std::push_heap(ah.begin(), ah.end());
+  ok = ok && std::is_heap(ah.begin(), ah.end());
+
+  return ok;
+}
+
+static_assert(test());
diff --git a/libstdc++-v3/testsuite/25_algorithms/reverse/constexpr.cc b/libstdc++-v3/testsuite/25_algorithms/reverse/constexpr.cc
new file mode 100644
index 00000000000..b55a9faf61e
--- /dev/null
+++ b/libstdc++-v3/testsuite/25_algorithms/reverse/constexpr.cc
@@ -0,0 +1,41 @@
+//
+// 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/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <algorithm>
+#include <array>
+
+#ifndef __cpp_lib_constexpr_swap_algorithms
+# error "Feature-test macro for constexpr swap algorithms missing"
+#elif __cpp_lib_constexpr_swap_algorithms < 201712L
+# error "Feature-test macro for constexpr swap algorithms has wrong value"
+#endif
+
+constexpr bool
+test()
+{
+  auto ok = true;
+
+  std::array<int, 12> ar0{{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}};
+
+  std::reverse(ar0.begin() + 2, ar0.begin() + 9);
+
+  return ar0[2] == 8 && ar0[8] == 2;
+}
+
+static_assert(test());
diff --git a/libstdc++-v3/testsuite/25_algorithms/rotate/constexpr.cc b/libstdc++-v3/testsuite/25_algorithms/rotate/constexpr.cc
new file mode 100644
index 00000000000..dbdaac3cdd2
--- /dev/null
+++ b/libstdc++-v3/testsuite/25_algorithms/rotate/constexpr.cc
@@ -0,0 +1,41 @@
+//
+// 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/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <algorithm>
+#include <array>
+
+#ifndef __cpp_lib_constexpr_swap_algorithms
+# error "Feature-test macro for constexpr swap algorithms missing"
+#elif __cpp_lib_constexpr_swap_algorithms < 201712L
+# error "Feature-test macro for constexpr swap algorithms has wrong value"
+#endif
+
+constexpr bool
+test()
+{
+  auto ok = true;
+
+  std::array<int, 12> ar0{{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}};
+
+  std::rotate(ar0.begin(), ar0.begin() + 5, ar0.end());
+
+  return ar0[0] == 5 && ar0[5] == 10;
+}
+
+static_assert(test());
diff --git a/libstdc++-v3/testsuite/25_algorithms/sort/constexpr.cc b/libstdc++-v3/testsuite/25_algorithms/sort/constexpr.cc
new file mode 100644
index 00000000000..732747302c9
--- /dev/null
+++ b/libstdc++-v3/testsuite/25_algorithms/sort/constexpr.cc
@@ -0,0 +1,46 @@
+// 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/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <algorithm>
+#include <array>
+
+#ifndef __cpp_lib_constexpr_swap_algorithms
+# error "Feature-test macro for constexpr swap algorithms missing"
+#elif __cpp_lib_constexpr_swap_algorithms < 201712L
+# error "Feature-test macro for constexpr swap algorithms has wrong value"
+#endif
+
+constexpr bool
+test()
+{
+  auto ok = true;
+
+  std::array<int, 12> ar0{{10, 0, 1, 2, 5, 6, 7, 8, 3, 4, 9, 11}};
+
+  std::sort(ar0.begin(), ar0.end());
+  ok = ok && std::is_sorted(ar0.begin(), ar0.end());
+
+  std::sort(ar0.begin(), ar0.end(), std::greater<>());
+  ok = ok && std::is_sorted(ar0.begin(), ar0.end(), std::greater<>());
+
+  return ok;
+}
+
+static_assert(test());
diff --git a/libstdc++-v3/testsuite/25_algorithms/sort_heap/constexpr.cc b/libstdc++-v3/testsuite/25_algorithms/sort_heap/constexpr.cc
new file mode 100644
index 00000000000..8be490307ba
--- /dev/null
+++ b/libstdc++-v3/testsuite/25_algorithms/sort_heap/constexpr.cc
@@ -0,0 +1,56 @@
+// 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/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <algorithm>
+#include <array>
+
+#ifndef __cpp_lib_constexpr_swap_algorithms
+# error "Feature-test macro for constexpr swap algorithms missing"
+#elif __cpp_lib_constexpr_swap_algorithms < 201712L
+# error "Feature-test macro for constexpr swap algorithms has wrong value"
+#endif
+
+constexpr bool
+test()
+{
+  auto ok = true;
+
+  std::array<int, 23>
+  ah{{0,
+      1, 2,
+      3, 4, 5, 6,
+      7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22}};
+
+  std::make_heap(ah.begin(), ah.begin() + 17);
+  ok = ok && std::is_heap(ah.begin(), ah.begin() + 17);
+
+  std::sort_heap(ah.begin(), ah.begin() + 17);
+  ok = ok && std::is_sorted(ah.begin(), ah.begin() + 17);
+
+  std::make_heap(ah.begin(), ah.begin() + 17, std::greater<>());
+  ok = ok && std::is_heap(ah.begin(), ah.begin() + 17, std::greater<>());
+
+  std::sort_heap(ah.begin(), ah.begin() + 17, std::greater<>());
+  ok = ok && std::is_sorted(ah.begin(), ah.begin() + 17, std::greater<>());
+
+  return ok;
+}
+
+static_assert(test());
diff --git a/libstdc++-v3/testsuite/25_algorithms/swap/constexpr.cc b/libstdc++-v3/testsuite/25_algorithms/swap/constexpr.cc
new file mode 100644
index 00000000000..5e417810ad7
--- /dev/null
+++ b/libstdc++-v3/testsuite/25_algorithms/swap/constexpr.cc
@@ -0,0 +1,47 @@
+// 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/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <algorithm>
+
+#ifndef __cpp_lib_constexpr_swap_algorithms
+# error "Feature-test macro for constexpr swap algorithms missing"
+#elif __cpp_lib_constexpr_swap_algorithms < 201712L
+# error "Feature-test macro for constexpr swap algorithms has wrong value"
+#endif
+
+constexpr bool
+test()
+{
+  auto ok = true;
+
+  double asc = 3.1415;
+  double bsc = 2.7182;
+  std::swap(asc, bsc);
+  ok = ok && asc == 2.7182 && bsc == 3.1415;
+
+  float arr[5]{0.0f, 1.0f, 2.0f, 3.0f, 4.0f};
+  float brr[5]{5.0f, 6.0f, 7.0f, 8.0f, 9.0f};
+  std::swap(arr, brr);
+  ok = ok && arr[2] == 7.0f && brr[2] == 2.0f;
+
+  return ok;
+}
+
+static_assert(test());
diff --git a/libstdc++-v3/testsuite/25_algorithms/swap_ranges/constexpr.cc b/libstdc++-v3/testsuite/25_algorithms/swap_ranges/constexpr.cc
new file mode 100644
index 00000000000..2293e317bba
--- /dev/null
+++ b/libstdc++-v3/testsuite/25_algorithms/swap_ranges/constexpr.cc
@@ -0,0 +1,44 @@
+// 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/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <algorithm>
+#include <array>
+
+#ifndef __cpp_lib_constexpr_swap_algorithms
+# error "Feature-test macro for constexpr swap algorithms missing"
+#elif __cpp_lib_constexpr_swap_algorithms < 201712L
+# error "Feature-test macro for constexpr swap algorithms has wrong value"
+#endif
+
+constexpr bool
+test()
+{
+  auto ok = true;
+
+  std::array<int, 12> ar0{{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}};
+  std::array<int, 12> ar1{{11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}};
+
+  const auto out01 = std::swap_ranges(ar0.begin(), ar0.begin() + 5,
+				      ar1.begin() + 2);
+
+  return ok = ar0[0] == 9 && ar1[2] == 0;
+}
+
+static_assert(test());

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH 1/3] C++20 constexpr lib part 1/3
  2019-08-01 15:47           ` Ed Smith-Rowland via gcc-patches
  2019-08-01 17:16             ` [PATCH 2/3] C++20 constexpr lib part 2/3 - swappish functions Ed Smith-Rowland via gcc-patches
@ 2019-08-01 19:45             ` Jonathan Wakely
  2019-08-02  1:04               ` Ed Smith-Rowland via gcc-patches
  1 sibling, 1 reply; 22+ messages in thread
From: Jonathan Wakely @ 2019-08-01 19:45 UTC (permalink / raw)
  To: Ed Smith-Rowland; +Cc: Ville Voutilainen, libstdc++, gcc-patches

On 01/08/19 11:47 -0400, Ed Smith-Rowland via libstdc++ wrote:
>On 8/1/19 6:56 AM, Jonathan Wakely wrote:
>>On 31/07/19 10:50 -0400, Ed Smith-Rowland via libstdc++ wrote:
>>>Here is the patch for
>>>
>>>* Implement C++20 p0202 - Add constexpr Modifiers to Functions in 
>>><algorithm> and <utility> Headers.
>>>
>>>* Implement C++20 p1023 - constexpr comparison operators for std::array.
>>>
>>>Relative to the last effort it is rebased on more recent trunk and 
>>>I added to <version>.
>>>
>>>There's some chance that I'll have to tweak the macros after the 
>>>draft comes in but I'd like to get this moving.?? I've got other 
>>>chunks of constexpr lib coming.?? This passes C++20 testing 
>>>onx86_64-linux.
>>>
>>>Ok?
>>
>>Calls to the new __memmove and __memcmp functions need to be qualified
>>with std:: to prevent ADL. I think we should rename those functions,
>>but that can happen later.
>
>IMHO, these concepts are too important to leave as an implementation detail.
>
>I suspect the committee will come crawling back to specify these with 
>real names.
>
>memory_copy, memory_compare, memory_move for C++23 anyone?

trivial_copy, trivial_compare, trivial_move?

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH 1/3] C++20 constexpr lib part 1/3
  2019-08-01 19:45             ` [PATCH 1/3] C++20 constexpr lib part 1/3 Jonathan Wakely
@ 2019-08-02  1:04               ` Ed Smith-Rowland via gcc-patches
  0 siblings, 0 replies; 22+ messages in thread
From: Ed Smith-Rowland via gcc-patches @ 2019-08-02  1:04 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: Ville Voutilainen, libstdc++, gcc-patches

On 8/1/19 3:45 PM, Jonathan Wakely wrote:
> On 01/08/19 11:47 -0400, Ed Smith-Rowland via libstdc++ wrote:
>> On 8/1/19 6:56 AM, Jonathan Wakely wrote:
>>> On 31/07/19 10:50 -0400, Ed Smith-Rowland via libstdc++ wrote:
>>>> Here is the patch for
>>>>
>>>> * Implement C++20 p0202 - Add constexpr Modifiers to Functions in 
>>>> <algorithm> and <utility> Headers.
>>>>
>>>> * Implement C++20 p1023 - constexpr comparison operators for 
>>>> std::array.
>>>>
>>>> Relative to the last effort it is rebased on more recent trunk and 
>>>> I added to <version>.
>>>>
>>>> There's some chance that I'll have to tweak the macros after the 
>>>> draft comes in but I'd like to get this moving.?? I've got other 
>>>> chunks of constexpr lib coming.?? This passes C++20 testing 
>>>> onx86_64-linux.
>>>>
>>>> Ok?
>>>
>>> Calls to the new __memmove and __memcmp functions need to be qualified
>>> with std:: to prevent ADL. I think we should rename those functions,
>>> but that can happen later.
>>
>> IMHO, these concepts are too important to leave as an implementation 
>> detail.
>>
>> I suspect the committee will come crawling back to specify these with 
>> real names.
>>
>> memory_copy, memory_compare, memory_move for C++23 anyone?
>
> trivial_copy, trivial_compare, trivial_move

Works for me. I'm sure there will be great bikeshed battles!

Ed


^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH 2/3] C++20 constexpr lib part 2/3 - swappish functions.
  2019-08-01 17:16             ` [PATCH 2/3] C++20 constexpr lib part 2/3 - swappish functions Ed Smith-Rowland via gcc-patches
@ 2019-08-13 11:24               ` Jonathan Wakely
  2019-08-14 15:59                 ` Ed Smith-Rowland via gcc-patches
  0 siblings, 1 reply; 22+ messages in thread
From: Jonathan Wakely @ 2019-08-13 11:24 UTC (permalink / raw)
  To: Ed Smith-Rowland; +Cc: libstdc++, Ville Voutilainen, gcc-patches

On 01/08/19 13:16 -0400, Ed Smith-Rowland via libstdc++ wrote:
>Greetings,
>
>Here is a patch for C++20 p0879 - Constexpr for swap and swap related 
>functions.
>
>This essentially constexprifies the rest of <algorithm>.
>
>Built and tested with C++20 (and pre-c++20) on x86_64-linux.
>
>Ok?
>
>Regards,
>
>Ed Smith-Rowland
>
>

>2019-08-01  Edward Smith-Rowland  <3dw4rd@verizon.net>
>
>	Implement C++20 p0879 - Constexpr for swap and swap related functions.
>	* include/bits/algorithmfwd.h (__cpp_lib_constexpr_swap_algorithms):
>	New macro. (iter_swap, make_heap, next_permutation, partial_sort_copy,

There should be a newline after "New macro." and before the next
parenthesized list of identifiers.

The parenthesized lists should not span multiple lines, so close and
reopen the parens, i.e.

        Implement C++20 p0879 - Constexpr for swap and swap related functions.
        * include/bits/algorithmfwd.h (__cpp_lib_constexpr_swap_algorithms):
        New macro.
        (iter_swap, make_heap, next_permutation, partial_sort_copy, pop_heap)
        (prev_permutation, push_heap, reverse, rotate, sort_heap, swap)
        (swap_ranges, nth_element, partial_sort, sort): Add constexpr.

>@@ -193,6 +193,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>
> #if __cplusplus > 201703L
> #  define __cpp_lib_constexpr_algorithms 201711L
>+#  define __cpp_lib_constexpr_swap_algorithms 201712L

Should this value be 201806L?

The new macro also needs to be added to <version>.

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH 2/3] C++20 constexpr lib part 2/3 - swappish functions.
  2019-08-13 11:24               ` Jonathan Wakely
@ 2019-08-14 15:59                 ` Ed Smith-Rowland via gcc-patches
  2019-08-14 16:19                   ` Jonathan Wakely
  0 siblings, 1 reply; 22+ messages in thread
From: Ed Smith-Rowland via gcc-patches @ 2019-08-14 15:59 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: libstdc++, Ville Voutilainen, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1716 bytes --]

On 8/13/19 7:14 AM, Jonathan Wakely wrote:
> On 01/08/19 13:16 -0400, Ed Smith-Rowland via libstdc++ wrote:
>> Greetings,
>>
>> Here is a patch for C++20 p0879 - Constexpr for swap and swap related 
>> functions.
>>
>> This essentially constexprifies the rest of <algorithm>.
>>
>> Built and tested with C++20 (and pre-c++20) on x86_64-linux.
>>
>> Ok?
>>
>> Regards,
>>
>> Ed Smith-Rowland
>>
>>
>
>> 2019-08-01?? Edward Smith-Rowland <3dw4rd@verizon.net>
>>
>> ????????Implement C++20 p0879 - Constexpr for swap and swap related 
>> functions.
>> ????????* include/bits/algorithmfwd.h (__cpp_lib_constexpr_swap_algorithms):
>> ????????New macro. (iter_swap, make_heap, next_permutation, 
>> partial_sort_copy,
>
> There should be a newline after "New macro." and before the next
> parenthesized list of identifiers.
>
> The parenthesized lists should not span multiple lines, so close and
> reopen the parens, i.e.
>
> ???????????? Implement C++20 p0879 - Constexpr for swap and swap related 
> functions.
> ???????????? * include/bits/algorithmfwd.h 
> (__cpp_lib_constexpr_swap_algorithms):
> ???????????? New macro.
> ???????????? (iter_swap, make_heap, next_permutation, partial_sort_copy, 
> pop_heap)
> ???????????? (prev_permutation, push_heap, reverse, rotate, sort_heap, swap)
> ???????????? (swap_ranges, nth_element, partial_sort, sort): Add constexpr.
>
>> @@ -193,6 +193,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>>
>> #if __cplusplus > 201703L
>> #?? define __cpp_lib_constexpr_algorithms 201711L
>> +#?? define __cpp_lib_constexpr_swap_algorithms 201712L
>
> Should this value be 201806L?
Indeed.
>
> The new macro also needs to be added to <version>.
>
Done.

I this OK after it passes testing?

Ed




[-- Attachment #2: CL_constexpr_swap --]
[-- Type: text/plain, Size: 2307 bytes --]

2019-08-14  Edward Smith-Rowland  <3dw4rd@verizon.net>

	Implement C++20 p0879 - Constexpr for swap and swap related functions.
	* include/bits/algorithmfwd.h (__cpp_lib_constexpr_swap_algorithms):
	New macro.
	* include/std/version: Ditto.
	(iter_swap, make_heap, next_permutation, partial_sort_copy, pop_heap)
	(prev_permutation, push_heap, reverse, rotate, sort_heap, swap)
	(swap_ranges, nth_element, partial_sort, sort): Add constexpr.
	* include/bits/move.h (swap): Add constexpr.
	* include/bits/stl_algo.h (__move_median_to_first, __reverse, reverse)
	(__gcd, __rotate, rotate, __partition, __heap_select)
	(__partial_sort_copy, partial_sort_copy, __unguarded_partition)
	(__unguarded_partition_pivot, __partial_sort, __introsort_loop, __sort)
	(__introselect, __chunk_insertion_sort, next_permutation)
	(prev_permutation, partition, partial_sort, nth_element, sort)
	(__iter_swap::iter_swap, iter_swap, swap_ranges): Add constexpr.
	* include/bits/stl_algobase.h (__iter_swap::iter_swap, iter_swap)
	(swap_ranges): Add constexpr.
	* include/bits/stl_heap.h (__push_heap, push_heap, __adjust_heap,
	__pop_heap, pop_heap, __make_heap, make_heap, __sort_heap, sort_heap):
	Add constexpr.
	* include/std/type_traits (swap): Add constexpr.
	* testsuite/25_algorithms/headers/algorithm/synopsis.cc: Add constexpr.
	* testsuite/25_algorithms/iter_swap/constexpr.cc: New test.
	* testsuite/25_algorithms/make_heap/constexpr.cc: New test.
	* testsuite/25_algorithms/next_permutation/constexpr.cc: New test.
	* testsuite/25_algorithms/nth_element/constexpr.cc: New test.
	* testsuite/25_algorithms/partial_sort/constexpr.cc: New test.
	* testsuite/25_algorithms/partial_sort_copy/constexpr.cc: New test.
	* testsuite/25_algorithms/partition/constexpr.cc: New test.
	* testsuite/25_algorithms/pop_heap/constexpr.cc: New test.
	* testsuite/25_algorithms/prev_permutation/constexpr.cc: New test.
	* testsuite/25_algorithms/push_heap/constexpr.cc: New test.
	* testsuite/25_algorithms/reverse/constexpr.cc: New test.
	* testsuite/25_algorithms/rotate/constexpr.cc: New test.
	* testsuite/25_algorithms/sort/constexpr.cc: New test.
	* testsuite/25_algorithms/sort_heap/constexpr.cc: New test.
	* testsuite/25_algorithms/swap/constexpr.cc: New test.
	* testsuite/25_algorithms/swap_ranges/constexpr.cc: New test.


[-- Attachment #3: patch_constexpr_swap --]
[-- Type: text/plain, Size: 52664 bytes --]

Index: include/bits/algorithmfwd.h
===================================================================
--- include/bits/algorithmfwd.h	(revision 274411)
+++ include/bits/algorithmfwd.h	(working copy)
@@ -193,6 +193,7 @@
 
 #if __cplusplus > 201703L
 #  define __cpp_lib_constexpr_algorithms 201711L
+#  define __cpp_lib_constexpr_swap_algorithms 201806L
 #endif
 
 #if __cplusplus >= 201103L
@@ -377,6 +378,7 @@
 #endif
 
   template<typename _FIter1, typename _FIter2>
+    _GLIBCXX20_CONSTEXPR
     void
     iter_swap(_FIter1, _FIter2);
 
@@ -391,10 +393,12 @@
     lower_bound(_FIter, _FIter, const _Tp&, _Compare);
 
   template<typename _RAIter>
+    _GLIBCXX20_CONSTEXPR
     void
     make_heap(_RAIter, _RAIter);
 
   template<typename _RAIter, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     void
     make_heap(_RAIter, _RAIter, _Compare);
 
@@ -478,10 +482,12 @@
   // mismatch
 
   template<typename _BIter>
+    _GLIBCXX20_CONSTEXPR
     bool
     next_permutation(_BIter, _BIter);
 
   template<typename _BIter, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     bool
     next_permutation(_BIter, _BIter, _Compare);
 
@@ -496,10 +502,12 @@
   // partial_sort
 
   template<typename _IIter, typename _RAIter>
+    _GLIBCXX20_CONSTEXPR
     _RAIter
     partial_sort_copy(_IIter, _IIter, _RAIter, _RAIter);
 
   template<typename _IIter, typename _RAIter, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     _RAIter
     partial_sort_copy(_IIter, _IIter, _RAIter, _RAIter, _Compare);
 
@@ -519,26 +527,32 @@
 #endif
 
   template<typename _RAIter>
+    _GLIBCXX20_CONSTEXPR
     void
     pop_heap(_RAIter, _RAIter);
 
   template<typename _RAIter, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     void
     pop_heap(_RAIter, _RAIter, _Compare);
 
   template<typename _BIter>
+    _GLIBCXX20_CONSTEXPR
     bool
     prev_permutation(_BIter, _BIter);
 
   template<typename _BIter, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     bool
     prev_permutation(_BIter, _BIter, _Compare);
 
   template<typename _RAIter>
+    _GLIBCXX20_CONSTEXPR
     void
     push_heap(_RAIter, _RAIter);
 
   template<typename _RAIter, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     void
     push_heap(_RAIter, _RAIter, _Compare);
 
@@ -579,6 +593,7 @@
   // replace_if
 
   template<typename _BIter>
+    _GLIBCXX20_CONSTEXPR
     void
     reverse(_BIter, _BIter);
 
@@ -590,6 +605,7 @@
   inline namespace _V2
   {
     template<typename _FIter>
+      _GLIBCXX20_CONSTEXPR
       _FIter
       rotate(_FIter, _FIter, _FIter);
   }
@@ -613,10 +629,12 @@
 #endif
 
   template<typename _RAIter>
+    _GLIBCXX20_CONSTEXPR
     void
     sort_heap(_RAIter, _RAIter);
 
   template<typename _RAIter, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     void
     sort_heap(_RAIter, _RAIter, _Compare);
 
@@ -628,15 +646,18 @@
   // For C++11 swap() is declared in <type_traits>.
 
   template<typename _Tp, size_t _Nm>
+    _GLIBCXX20_CONSTEXPR
     inline void
     swap(_Tp& __a, _Tp& __b);
 
   template<typename _Tp, size_t _Nm>
+    _GLIBCXX20_CONSTEXPR
     inline void
     swap(_Tp (&__a)[_Nm], _Tp (&__b)[_Nm]);
 #endif
 
   template<typename _FIter1, typename _FIter2>
+    _GLIBCXX20_CONSTEXPR
     _FIter2
     swap_ranges(_FIter1, _FIter1, _FIter2);
 
@@ -783,22 +804,27 @@
     mismatch(_IIter1, _IIter1, _IIter2, _BinaryPredicate);
 
   template<typename _RAIter>
+    _GLIBCXX20_CONSTEXPR
     void
     nth_element(_RAIter, _RAIter, _RAIter);
 
   template<typename _RAIter, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     void
     nth_element(_RAIter, _RAIter, _RAIter, _Compare);
 
   template<typename _RAIter>
+    _GLIBCXX20_CONSTEXPR
     void
     partial_sort(_RAIter, _RAIter, _RAIter);
 
   template<typename _RAIter, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     void
     partial_sort(_RAIter, _RAIter, _RAIter, _Compare);
 
   template<typename _BIter, typename _Predicate>
+    _GLIBCXX20_CONSTEXPR
     _BIter
     partition(_BIter, _BIter, _Predicate);
 
@@ -892,10 +918,12 @@
     set_union(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, _Compare);
 
   template<typename _RAIter>
+    _GLIBCXX20_CONSTEXPR
     void
     sort(_RAIter, _RAIter);
 
   template<typename _RAIter, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     void
     sort(_RAIter, _RAIter, _Compare);
 
Index: include/bits/move.h
===================================================================
--- include/bits/move.h	(revision 274411)
+++ include/bits/move.h	(working copy)
@@ -175,6 +175,7 @@
    *  @return   Nothing.
   */
   template<typename _Tp>
+    _GLIBCXX20_CONSTEXPR
     inline
 #if __cplusplus >= 201103L
     typename enable_if<__and_<__not_<__is_tuple_like<_Tp>>,
@@ -199,6 +200,7 @@
   // DR 809. std::swap should be overloaded for array types.
   /// Swap the contents of two arrays.
   template<typename _Tp, size_t _Nm>
+    _GLIBCXX20_CONSTEXPR
     inline
 #if __cplusplus >= 201103L
     typename enable_if<__is_swappable<_Tp>::value>::type
Index: include/bits/stl_algo.h
===================================================================
--- include/bits/stl_algo.h	(revision 274411)
+++ include/bits/stl_algo.h	(working copy)
@@ -74,6 +74,7 @@
 
   /// Swaps the median value of *__a, *__b and *__c under __comp to *__result
   template<typename _Iterator, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     void
     __move_median_to_first(_Iterator __result,_Iterator __a, _Iterator __b,
 			   _Iterator __c, _Compare __comp)
@@ -1162,6 +1163,7 @@
    *  overloaded for bidirectional iterators.
   */
   template<typename _BidirectionalIterator>
+    _GLIBCXX20_CONSTEXPR
     void
     __reverse(_BidirectionalIterator __first, _BidirectionalIterator __last,
 	      bidirectional_iterator_tag)
@@ -1182,6 +1184,7 @@
    *  overloaded for random access iterators.
   */
   template<typename _RandomAccessIterator>
+    _GLIBCXX20_CONSTEXPR
     void
     __reverse(_RandomAccessIterator __first, _RandomAccessIterator __last,
 	      random_access_iterator_tag)
@@ -1210,6 +1213,7 @@
    *  swaps @p *(__first+i) and @p *(__last-(i+1))
   */
   template<typename _BidirectionalIterator>
+    _GLIBCXX20_CONSTEXPR
     inline void
     reverse(_BidirectionalIterator __first, _BidirectionalIterator __last)
     {
@@ -1263,6 +1267,7 @@
    *  It returns the greatest common divisor of two integer values.
   */
   template<typename _EuclideanRingElement>
+    _GLIBCXX20_CONSTEXPR
     _EuclideanRingElement
     __gcd(_EuclideanRingElement __m, _EuclideanRingElement __n)
     {
@@ -1280,6 +1285,7 @@
 
   /// This is a helper function for the rotate algorithm.
   template<typename _ForwardIterator>
+    _GLIBCXX20_CONSTEXPR
     _ForwardIterator
     __rotate(_ForwardIterator __first,
 	     _ForwardIterator __middle,
@@ -1321,6 +1327,7 @@
 
    /// This is a helper function for the rotate algorithm.
   template<typename _BidirectionalIterator>
+    _GLIBCXX20_CONSTEXPR
     _BidirectionalIterator
     __rotate(_BidirectionalIterator __first,
 	     _BidirectionalIterator __middle,
@@ -1359,6 +1366,7 @@
 
   /// This is a helper function for the rotate algorithm.
   template<typename _RandomAccessIterator>
+    _GLIBCXX20_CONSTEXPR
     _RandomAccessIterator
     __rotate(_RandomAccessIterator __first,
 	     _RandomAccessIterator __middle,
@@ -1465,6 +1473,7 @@
    *  for each @p n in the range @p [0,__last-__first).
   */
   template<typename _ForwardIterator>
+    _GLIBCXX20_CONSTEXPR
     inline _ForwardIterator
     rotate(_ForwardIterator __first, _ForwardIterator __middle,
 	   _ForwardIterator __last)
@@ -1520,6 +1529,7 @@
 
   /// This is a helper function...
   template<typename _ForwardIterator, typename _Predicate>
+    _GLIBCXX20_CONSTEXPR
     _ForwardIterator
     __partition(_ForwardIterator __first, _ForwardIterator __last,
 		_Predicate __pred, forward_iterator_tag)
@@ -1545,6 +1555,7 @@
 
   /// This is a helper function...
   template<typename _BidirectionalIterator, typename _Predicate>
+    _GLIBCXX20_CONSTEXPR
     _BidirectionalIterator
     __partition(_BidirectionalIterator __first, _BidirectionalIterator __last,
 		_Predicate __pred, bidirectional_iterator_tag)
@@ -1699,6 +1710,7 @@
 
   /// This is a helper function for the sort routines.
   template<typename _RandomAccessIterator, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     void
     __heap_select(_RandomAccessIterator __first,
 		  _RandomAccessIterator __middle,
@@ -1714,6 +1726,7 @@
 
   template<typename _InputIterator, typename _RandomAccessIterator,
 	   typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     _RandomAccessIterator
     __partial_sort_copy(_InputIterator __first, _InputIterator __last,
 			_RandomAccessIterator __result_first,
@@ -1768,6 +1781,7 @@
    *  The value returned is @p __result_first+N.
   */
   template<typename _InputIterator, typename _RandomAccessIterator>
+    _GLIBCXX20_CONSTEXPR
     inline _RandomAccessIterator
     partial_sort_copy(_InputIterator __first, _InputIterator __last,
 		      _RandomAccessIterator __result_first,
@@ -1818,6 +1832,7 @@
   */
   template<typename _InputIterator, typename _RandomAccessIterator,
 	   typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     inline _RandomAccessIterator
     partial_sort_copy(_InputIterator __first, _InputIterator __last,
 		      _RandomAccessIterator __result_first,
@@ -1931,6 +1946,7 @@
 
   /// This is a helper function...
   template<typename _RandomAccessIterator, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     _RandomAccessIterator
     __unguarded_partition(_RandomAccessIterator __first,
 			  _RandomAccessIterator __last,
@@ -1952,6 +1968,7 @@
 
   /// This is a helper function...
   template<typename _RandomAccessIterator, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     inline _RandomAccessIterator
     __unguarded_partition_pivot(_RandomAccessIterator __first,
 				_RandomAccessIterator __last, _Compare __comp)
@@ -1963,6 +1980,7 @@
     }
 
   template<typename _RandomAccessIterator, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     inline void
     __partial_sort(_RandomAccessIterator __first,
 		   _RandomAccessIterator __middle,
@@ -1975,6 +1993,7 @@
 
   /// This is a helper function for the sort routine.
   template<typename _RandomAccessIterator, typename _Size, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     void
     __introsort_loop(_RandomAccessIterator __first,
 		     _RandomAccessIterator __last,
@@ -1998,6 +2017,7 @@
   // sort
 
   template<typename _RandomAccessIterator, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     inline void
     __sort(_RandomAccessIterator __first, _RandomAccessIterator __last,
 	   _Compare __comp)
@@ -2012,6 +2032,7 @@
     }
 
   template<typename _RandomAccessIterator, typename _Size, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     void
     __introselect(_RandomAccessIterator __first, _RandomAccessIterator __nth,
 		  _RandomAccessIterator __last, _Size __depth_limit,
@@ -2728,6 +2749,7 @@
 
   template<typename _RandomAccessIterator, typename _Distance,
 	   typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     void
     __chunk_insertion_sort(_RandomAccessIterator __first,
 			   _RandomAccessIterator __last,
@@ -2997,6 +3019,7 @@
    *  is the largest of the set, the smallest is generated and false returned.
   */
   template<typename _BidirectionalIterator>
+    _GLIBCXX20_CONSTEXPR
     inline bool
     next_permutation(_BidirectionalIterator __first,
 		     _BidirectionalIterator __last)
@@ -3029,6 +3052,7 @@
    *  smallest is generated and false returned.
   */
   template<typename _BidirectionalIterator, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     inline bool
     next_permutation(_BidirectionalIterator __first,
 		     _BidirectionalIterator __last, _Compare __comp)
@@ -3098,6 +3122,7 @@
    *  returned.
   */
   template<typename _BidirectionalIterator>
+    _GLIBCXX20_CONSTEXPR
     inline bool
     prev_permutation(_BidirectionalIterator __first,
 		     _BidirectionalIterator __last)
@@ -3130,6 +3155,7 @@
    *  the largest is generated and false returned.
   */
   template<typename _BidirectionalIterator, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     inline bool
     prev_permutation(_BidirectionalIterator __first,
 		     _BidirectionalIterator __last, _Compare __comp)
@@ -4757,6 +4783,7 @@
    *  @p stable_partition() if this is needed.
   */
   template<typename _ForwardIterator, typename _Predicate>
+    _GLIBCXX20_CONSTEXPR
     inline _ForwardIterator
     partition(_ForwardIterator __first, _ForwardIterator __last,
 	      _Predicate   __pred)
@@ -4790,6 +4817,7 @@
    *  the range @p [__middle,__last) then *j<*i and *k<*i are both false.
   */
   template<typename _RandomAccessIterator>
+    _GLIBCXX20_CONSTEXPR
     inline void
     partial_sort(_RandomAccessIterator __first,
 		 _RandomAccessIterator __middle,
@@ -4828,6 +4856,7 @@
    *  are both false.
   */
   template<typename _RandomAccessIterator, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     inline void
     partial_sort(_RandomAccessIterator __first,
 		 _RandomAccessIterator __middle,
@@ -4864,6 +4893,7 @@
    *  holds that *j < *i is false.
   */
   template<typename _RandomAccessIterator>
+    _GLIBCXX20_CONSTEXPR
     inline void
     nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth,
 		_RandomAccessIterator __last)
@@ -4903,6 +4933,7 @@
    *  holds that @p __comp(*j,*i) is false.
   */
   template<typename _RandomAccessIterator, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     inline void
     nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth,
 		_RandomAccessIterator __last, _Compare __comp)
@@ -4940,6 +4971,7 @@
    *  @p stable_sort() if this is needed.
   */
   template<typename _RandomAccessIterator>
+    _GLIBCXX20_CONSTEXPR
     inline void
     sort(_RandomAccessIterator __first, _RandomAccessIterator __last)
     {
@@ -4970,6 +5002,7 @@
    *  @p stable_sort() if this is needed.
   */
   template<typename _RandomAccessIterator, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     inline void
     sort(_RandomAccessIterator __first, _RandomAccessIterator __last,
 	 _Compare __comp)
Index: include/bits/stl_algobase.h
===================================================================
--- include/bits/stl_algobase.h	(revision 274411)
+++ include/bits/stl_algobase.h	(working copy)
@@ -136,6 +136,7 @@
     struct __iter_swap
     {
       template<typename _ForwardIterator1, typename _ForwardIterator2>
+	_GLIBCXX20_CONSTEXPR
 	static void
 	iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
 	{
@@ -151,6 +152,7 @@
     struct __iter_swap<true>
     {
       template<typename _ForwardIterator1, typename _ForwardIterator2>
+	_GLIBCXX20_CONSTEXPR
 	static void
 	iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
 	{
@@ -170,6 +172,7 @@
    *  iterators themselves.
   */
   template<typename _ForwardIterator1, typename _ForwardIterator2>
+    _GLIBCXX20_CONSTEXPR
     inline void
     iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
     {
@@ -216,6 +219,7 @@
    *  The ranges must not overlap.
   */
   template<typename _ForwardIterator1, typename _ForwardIterator2>
+    _GLIBCXX20_CONSTEXPR
     _ForwardIterator2
     swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
 		_ForwardIterator2 __first2)
Index: include/bits/stl_heap.h
===================================================================
--- include/bits/stl_heap.h	(revision 274411)
+++ include/bits/stl_heap.h	(working copy)
@@ -129,6 +129,7 @@
 
   template<typename _RandomAccessIterator, typename _Distance, typename _Tp,
 	   typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     void
     __push_heap(_RandomAccessIterator __first,
 		_Distance __holeIndex, _Distance __topIndex, _Tp __value,
@@ -155,6 +156,7 @@
    *  [__first,__last) is a valid heap.
   */
   template<typename _RandomAccessIterator>
+    _GLIBCXX20_CONSTEXPR
     inline void
     push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
     {
@@ -190,6 +192,7 @@
    *  performed using comp.
   */
   template<typename _RandomAccessIterator, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     inline void
     push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last,
 	      _Compare __comp)
@@ -215,6 +218,7 @@
 
   template<typename _RandomAccessIterator, typename _Distance,
 	   typename _Tp, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     void
     __adjust_heap(_RandomAccessIterator __first, _Distance __holeIndex,
 		  _Distance __len, _Tp __value, _Compare __comp)
@@ -244,6 +248,7 @@
     }
 
   template<typename _RandomAccessIterator, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     inline void
     __pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last,
 	       _RandomAccessIterator __result, _Compare& __comp)
@@ -272,6 +277,7 @@
    *  heap.
   */
   template<typename _RandomAccessIterator>
+    _GLIBCXX20_CONSTEXPR
     inline void
     pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
     {
@@ -305,6 +311,7 @@
    *  heap.  Comparisons are made using comp.
   */
   template<typename _RandomAccessIterator, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     inline void
     pop_heap(_RandomAccessIterator __first,
 	     _RandomAccessIterator __last, _Compare __comp)
@@ -327,6 +334,7 @@
     }
 
   template<typename _RandomAccessIterator, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     void
     __make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last,
 		_Compare& __comp)
@@ -361,6 +369,7 @@
    *  This operation makes the elements in [__first,__last) into a heap.
   */
   template<typename _RandomAccessIterator>
+    _GLIBCXX20_CONSTEXPR
     inline void
     make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
     {
@@ -387,6 +396,7 @@
    *  Comparisons are made using __comp.
   */
   template<typename _RandomAccessIterator, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     inline void
     make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last,
 	      _Compare __comp)
@@ -403,6 +413,7 @@
     }
 
   template<typename _RandomAccessIterator, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     void
     __sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last,
 		_Compare& __comp)
@@ -423,6 +434,7 @@
    *  This operation sorts the valid heap in the range [__first,__last).
   */
   template<typename _RandomAccessIterator>
+    _GLIBCXX20_CONSTEXPR
     inline void
     sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
     {
@@ -450,6 +462,7 @@
    *  Comparisons are made using __comp.
   */
   template<typename _RandomAccessIterator, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     inline void
     sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last,
 	      _Compare __comp)
Index: include/std/type_traits
===================================================================
--- include/std/type_traits	(revision 274411)
+++ include/std/type_traits	(working copy)
@@ -2695,6 +2695,7 @@
     { };
 
   template<typename _Tp>
+    _GLIBCXX20_CONSTEXPR
     inline
     typename enable_if<__and_<__not_<__is_tuple_like<_Tp>>,
 			      is_move_constructible<_Tp>,
@@ -2704,6 +2705,7 @@
 	            is_nothrow_move_assignable<_Tp>>::value);
 
   template<typename _Tp, size_t _Nm>
+    _GLIBCXX20_CONSTEXPR
     inline
     typename enable_if<__is_swappable<_Tp>::value>::type
     swap(_Tp (&__a)[_Nm], _Tp (&__b)[_Nm])
Index: include/std/version
===================================================================
--- include/std/version	(revision 274411)
+++ include/std/version	(working copy)
@@ -154,6 +154,7 @@
 #define __cpp_lib_bind_front 201907L
 #define __cpp_lib_bounded_array_traits 201902L
 #define __cpp_lib_constexpr_algorithms 201711L
+#define __cpp_lib_constexpr_swap_algorithms 201806L
 #if __cpp_impl_destroying_delete
 # define __cpp_lib_destroying_delete 201806L
 #endif
Index: testsuite/25_algorithms/headers/algorithm/synopsis.cc
===================================================================
--- testsuite/25_algorithms/headers/algorithm/synopsis.cc	(revision 274411)
+++ testsuite/25_algorithms/headers/algorithm/synopsis.cc	(working copy)
@@ -165,10 +165,12 @@
   // 25.2.2, swap:
 #if __cplusplus < 201103L
   template<typename _Tp> 
+    _GLIBCXX20_CONSTEXPR
     void 
     swap(_Tp&, _Tp& b);
 
   template<typename _Tp, size_t _Nm>
+    _GLIBCXX20_CONSTEXPR
     void
     swap(_Tp (&)[_Nm], _Tp (&)[_Nm]);
 #else
@@ -178,10 +180,12 @@
 #endif
 
   template<typename _FIter1, typename _FIter2>
+    _GLIBCXX20_CONSTEXPR
     _FIter2 
     swap_ranges(_FIter1 first1, _FIter1, _FIter2);
 
   template<typename _FIter1, typename _FIter2>
+    _GLIBCXX20_CONSTEXPR
     void 
     iter_swap(_FIter1, _FIter2 b);
 
@@ -295,6 +299,7 @@
     unique_copy(_IIter, _IIter, _OIter, _BinaryPredicate);
 
   template<typename _BIter>
+    _GLIBCXX20_CONSTEXPR
     void 
     reverse(_BIter, _BIter);
 
@@ -304,6 +309,7 @@
     reverse_copy(_BIter, _BIter, _OIter);
 
   template<typename _FIter>
+    _GLIBCXX20_CONSTEXPR
     void 
     rotate(_FIter, _FIter, _FIter);
 
@@ -322,6 +328,7 @@
 
   // 25.2.12, partitions:
   template<typename _BIter, typename _Predicate>
+    _GLIBCXX20_CONSTEXPR
     _BIter 
     partition(_BIter, _BIter, _Predicate);
 
@@ -332,10 +339,12 @@
   // 25.3, sorting and related operations:
   // 25.3.1, sorting:
   template<typename _RAIter>
+    _GLIBCXX20_CONSTEXPR
     void 
     sort(_RAIter, _RAIter);
 
   template<typename _RAIter, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     void 
     sort(_RAIter, _RAIter, _Compare);
 
@@ -348,26 +357,32 @@
     stable_sort(_RAIter, _RAIter, _Compare);
 
   template<typename _RAIter>
+    _GLIBCXX20_CONSTEXPR
     void 
     partial_sort(_RAIter, _RAIter, _RAIter);
 
   template<typename _RAIter, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     void 
     partial_sort(_RAIter, _RAIter, _RAIter, _Compare);
 
   template<typename _IIter, typename _RAIter>
+    _GLIBCXX20_CONSTEXPR
     _RAIter
     partial_sort_copy(_IIter, _IIter, _RAIter, _RAIter);
 
   template<typename _IIter, typename _RAIter, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     _RAIter
     partial_sort_copy(_IIter, _IIter, _RAIter, _RAIter, _Compare);
 
   template<typename _RAIter>
+    _GLIBCXX20_CONSTEXPR
     void 
     nth_element(_RAIter, _RAIter, _RAIter);
 
   template<typename _RAIter, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     void 
     nth_element(_RAIter, _RAIter, _RAIter, _Compare);
 
@@ -490,34 +505,42 @@
 
   // 25.3.6, heap operations:
   template<typename _RAIter>
+    _GLIBCXX20_CONSTEXPR
     void 
     push_heap(_RAIter, _RAIter);
 
   template<typename _RAIter, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     void 
     push_heap(_RAIter, _RAIter, _Compare);
 
   template<typename _RAIter>
+    _GLIBCXX20_CONSTEXPR
     void 
     pop_heap(_RAIter, _RAIter);
 
   template<typename _RAIter, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     void 
     pop_heap(_RAIter, _RAIter, _Compare);
 
   template<typename _RAIter>
+    _GLIBCXX20_CONSTEXPR
     void 
     make_heap(_RAIter, _RAIter);
 
   template<typename _RAIter, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     void 
     make_heap(_RAIter, _RAIter, _Compare);
 
   template<typename _RAIter>
+    _GLIBCXX20_CONSTEXPR
     void 
     sort_heap(_RAIter, _RAIter);
 
   template<typename _RAIter, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     void 
     sort_heap(_RAIter, _RAIter, _Compare);
 
@@ -668,18 +691,22 @@
 
   // 25.3.9, permutations
   template<typename _BIter>
+    _GLIBCXX20_CONSTEXPR
     bool 
     next_permutation(_BIter, _BIter);
 
   template<typename _BIter, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     bool 
     next_permutation(_BIter, _BIter, _Compare);
 
   template<typename _BIter>
+    _GLIBCXX20_CONSTEXPR
     bool 
     prev_permutation(_BIter, _BIter);
 
   template<typename _BIter, typename _Compare>
+    _GLIBCXX20_CONSTEXPR
     bool 
     prev_permutation(_BIter, _BIter, _Compare);
 }
Index: testsuite/25_algorithms/iter_swap/constexpr.cc
===================================================================
--- testsuite/25_algorithms/iter_swap/constexpr.cc	(nonexistent)
+++ testsuite/25_algorithms/iter_swap/constexpr.cc	(working copy)
@@ -0,0 +1,42 @@
+// 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/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <algorithm>
+#include <array>
+
+#ifndef __cpp_lib_constexpr_swap_algorithms
+# error "Feature-test macro for constexpr swap algorithms missing"
+#elif __cpp_lib_constexpr_swap_algorithms < 201806L
+# error "Feature-test macro for constexpr swap algorithms has wrong value"
+#endif
+
+constexpr bool
+test()
+{
+  auto ok = true;
+
+  std::array<int, 12> ar0{{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}};
+
+  std::iter_swap(ar0.begin() + 2, ar0.begin() + 5);
+
+  return ok = ar0[2] == 5 && ar0[5] == 2;
+}
+
+static_assert(test());
Index: testsuite/25_algorithms/make_heap/constexpr.cc
===================================================================
--- testsuite/25_algorithms/make_heap/constexpr.cc	(nonexistent)
+++ testsuite/25_algorithms/make_heap/constexpr.cc	(working copy)
@@ -0,0 +1,47 @@
+// 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/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <algorithm>
+#include <array>
+
+#ifndef __cpp_lib_constexpr_swap_algorithms
+# error "Feature-test macro for constexpr swap algorithms missing"
+#elif __cpp_lib_constexpr_swap_algorithms < 201806L
+# error "Feature-test macro for constexpr swap algorithms has wrong value"
+#endif
+
+constexpr bool
+test()
+{
+  auto ok = true;
+
+  std::array<int, 23>
+  ah{{0,
+      1, 2,
+      3, 4, 5, 6,
+      7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22}};
+
+  std::make_heap(ah.begin(), ah.begin() + 17);
+  ok = ok && std::is_heap(ah.begin(), ah.begin() + 17);
+
+  return ok;
+}
+
+static_assert(test());
Index: testsuite/25_algorithms/next_permutation/constexpr.cc
===================================================================
--- testsuite/25_algorithms/next_permutation/constexpr.cc	(nonexistent)
+++ testsuite/25_algorithms/next_permutation/constexpr.cc	(working copy)
@@ -0,0 +1,42 @@
+// 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/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <algorithm>
+#include <array>
+
+#ifndef __cpp_lib_constexpr_swap_algorithms
+# error "Feature-test macro for constexpr swap algorithms missing"
+#elif __cpp_lib_constexpr_swap_algorithms < 201806L
+# error "Feature-test macro for constexpr swap algorithms has wrong value"
+#endif
+
+constexpr bool
+test()
+{
+  auto ok = true;
+
+  std::array<int, 12> ar0{{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}};
+
+  std::next_permutation(ar0.begin(), ar0.end());
+
+  return ok = ar0[11] == 10 && ar0[10] == 11;
+}
+
+static_assert(test());
Index: testsuite/25_algorithms/nth_element/constexpr.cc
===================================================================
--- testsuite/25_algorithms/nth_element/constexpr.cc	(nonexistent)
+++ testsuite/25_algorithms/nth_element/constexpr.cc	(working copy)
@@ -0,0 +1,47 @@
+// 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/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <algorithm>
+#include <array>
+
+#ifndef __cpp_lib_constexpr_swap_algorithms
+# error "Feature-test macro for constexpr swap algorithms missing"
+#elif __cpp_lib_constexpr_swap_algorithms < 201806L
+# error "Feature-test macro for constexpr swap algorithms has wrong value"
+#endif
+
+constexpr bool
+test()
+{
+  auto ok = true;
+
+  std::array<int, 12> ar0{{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}};
+
+  std::nth_element(ar0.begin(), ar0.begin() + 5, ar0.end());
+  ok = ok && ar0[5] == 5;
+
+  std::sort(ar0.begin(), ar0.end(), std::greater<>());
+  std::nth_element(ar0.begin(), ar0.begin() + 5, ar0.end(), std::greater<>());
+  ok = ok && ar0[5] == 6;
+
+  return ok;
+}
+
+static_assert(test());
Index: testsuite/25_algorithms/partial_sort/constexpr.cc
===================================================================
--- testsuite/25_algorithms/partial_sort/constexpr.cc	(nonexistent)
+++ testsuite/25_algorithms/partial_sort/constexpr.cc	(working copy)
@@ -0,0 +1,46 @@
+// 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/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <algorithm>
+#include <array>
+
+#ifndef __cpp_lib_constexpr_swap_algorithms
+# error "Feature-test macro for constexpr swap algorithms missing"
+#elif __cpp_lib_constexpr_swap_algorithms < 201806L
+# error "Feature-test macro for constexpr swap algorithms has wrong value"
+#endif
+
+constexpr bool
+test()
+{
+  auto ok = true;
+
+  std::array<int, 12> ar0{{0, 1, 7, 8, 9, 2, 3, 4, 5, 6, 10, 11}};
+
+  std::partial_sort(ar0.begin(), ar0.begin() + 5, ar0.end());
+  ok = ok && ar0[0] == 0 && ar0[4] == 4;
+
+  std::partial_sort(ar0.begin(), ar0.begin() + 5, ar0.end(), std::greater<>());
+  ok = ok && ar0[0] == 11 && ar0[4] == 7;
+
+  return ok;
+}
+
+static_assert(test());
Index: testsuite/25_algorithms/partial_sort_copy/constexpr.cc
===================================================================
--- testsuite/25_algorithms/partial_sort_copy/constexpr.cc	(nonexistent)
+++ testsuite/25_algorithms/partial_sort_copy/constexpr.cc	(working copy)
@@ -0,0 +1,47 @@
+// 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/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <algorithm>
+#include <array>
+
+#ifndef __cpp_lib_constexpr_swap_algorithms
+# error "Feature-test macro for constexpr swap algorithms missing"
+#elif __cpp_lib_constexpr_swap_algorithms < 201806L
+# error "Feature-test macro for constexpr swap algorithms has wrong value"
+#endif
+
+constexpr bool
+test()
+{
+  auto ok = true;
+
+  const std::array<int, 12> ar0{{0, 7, 8, 9, 1, 2, 5, 6, 10, 3, 4, 11}};
+  std::array<int, 12> or0{{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
+
+  std::partial_sort_copy(ar0.begin() + 5, ar0.begin() + 10,
+			 or0.begin(), or0.begin() + 5);
+
+  std::partial_sort_copy(ar0.begin() + 5, ar0.begin() + 10,
+			 or0.begin(), or0.begin() + 5, std::greater<>());
+
+  return ok;
+}
+
+static_assert(test());
Index: testsuite/25_algorithms/partition/constexpr.cc
===================================================================
--- testsuite/25_algorithms/partition/constexpr.cc	(nonexistent)
+++ testsuite/25_algorithms/partition/constexpr.cc	(working copy)
@@ -0,0 +1,44 @@
+// 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/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <algorithm>
+#include <array>
+
+#ifndef __cpp_lib_constexpr_swap_algorithms
+# error "Feature-test macro for constexpr swap algorithms missing"
+#elif __cpp_lib_constexpr_swap_algorithms < 201806L
+# error "Feature-test macro for constexpr swap algorithms has wrong value"
+#endif
+
+constexpr bool
+test()
+{
+  auto ok = true;
+
+  std::array<int, 12> ar0{{10, 0, 5, 1, 2, 6, 7, 8, 3, 4, 9, 11}};
+
+  auto iter1 = std::partition(ar0.begin(), ar0.end(),
+			      [](int i){ return i < 7; });
+  ok = ok && *iter1 == 8;
+
+  return ok;
+}
+
+static_assert(test());
Index: testsuite/25_algorithms/pop_heap/constexpr.cc
===================================================================
--- testsuite/25_algorithms/pop_heap/constexpr.cc	(nonexistent)
+++ testsuite/25_algorithms/pop_heap/constexpr.cc	(working copy)
@@ -0,0 +1,53 @@
+// 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/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <algorithm>
+#include <array>
+
+#ifndef __cpp_lib_constexpr_swap_algorithms
+# error "Feature-test macro for constexpr swap algorithms missing"
+#elif __cpp_lib_constexpr_swap_algorithms < 201806L
+# error "Feature-test macro for constexpr swap algorithms has wrong value"
+#endif
+
+constexpr bool
+test()
+{
+  auto ok = true;
+
+  std::array<int, 23>
+  ah{{0,
+      1, 2,
+      3, 4, 5, 6,
+      7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22}};
+
+  std::make_heap(ah.begin(), ah.end());
+  ok = ok && std::is_heap(ah.begin(), ah.end());
+
+  std::pop_heap(ah.begin(), ah.end());
+  std::pop_heap(ah.begin(), ah.end() - 1);
+  std::pop_heap(ah.begin(), ah.end() - 2);
+  ok = ok && std::is_heap(ah.begin(), ah.end() - 3)
+	  && !std::is_heap(ah.begin(), ah.end());
+
+  return ok;
+}
+
+static_assert(test());
Index: testsuite/25_algorithms/prev_permutation/constexpr.cc
===================================================================
--- testsuite/25_algorithms/prev_permutation/constexpr.cc	(nonexistent)
+++ testsuite/25_algorithms/prev_permutation/constexpr.cc	(working copy)
@@ -0,0 +1,42 @@
+// 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/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <algorithm>
+#include <array>
+
+#ifndef __cpp_lib_constexpr_swap_algorithms
+# error "Feature-test macro for constexpr swap algorithms missing"
+#elif __cpp_lib_constexpr_swap_algorithms < 201806L
+# error "Feature-test macro for constexpr swap algorithms has wrong value"
+#endif
+
+constexpr bool
+test()
+{
+  auto ok = true;
+
+  std::array<int, 12> ar0{{1, 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}};
+
+  std::prev_permutation(ar0.begin(), ar0.end());
+
+  return ok = ar0[0] == 0;
+}
+
+static_assert(test());
Index: testsuite/25_algorithms/push_heap/constexpr.cc
===================================================================
--- testsuite/25_algorithms/push_heap/constexpr.cc	(nonexistent)
+++ testsuite/25_algorithms/push_heap/constexpr.cc	(working copy)
@@ -0,0 +1,52 @@
+// 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/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <algorithm>
+#include <array>
+
+#ifndef __cpp_lib_constexpr_swap_algorithms
+# error "Feature-test macro for constexpr swap algorithms missing"
+#elif __cpp_lib_constexpr_swap_algorithms < 201806L
+# error "Feature-test macro for constexpr swap algorithms has wrong value"
+#endif
+
+constexpr bool
+test()
+{
+  auto ok = true;
+
+  std::array<int, 23>
+  ah{{0,
+      1, 2,
+      3, 4, 5, 6,
+      7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22}};
+
+  std::make_heap(ah.begin(), ah.end() - 3);
+  ok = ok && std::is_heap(ah.begin(), ah.end() - 3);
+
+  std::push_heap(ah.begin(), ah.end() - 2);
+  std::push_heap(ah.begin(), ah.end() - 1);
+  std::push_heap(ah.begin(), ah.end());
+  ok = ok && std::is_heap(ah.begin(), ah.end());
+
+  return ok;
+}
+
+static_assert(test());
Index: testsuite/25_algorithms/reverse/constexpr.cc
===================================================================
--- testsuite/25_algorithms/reverse/constexpr.cc	(nonexistent)
+++ testsuite/25_algorithms/reverse/constexpr.cc	(working copy)
@@ -0,0 +1,41 @@
+//
+// 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/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <algorithm>
+#include <array>
+
+#ifndef __cpp_lib_constexpr_swap_algorithms
+# error "Feature-test macro for constexpr swap algorithms missing"
+#elif __cpp_lib_constexpr_swap_algorithms < 201806L
+# error "Feature-test macro for constexpr swap algorithms has wrong value"
+#endif
+
+constexpr bool
+test()
+{
+  auto ok = true;
+
+  std::array<int, 12> ar0{{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}};
+
+  std::reverse(ar0.begin() + 2, ar0.begin() + 9);
+
+  return ar0[2] == 8 && ar0[8] == 2;
+}
+
+static_assert(test());
Index: testsuite/25_algorithms/rotate/constexpr.cc
===================================================================
--- testsuite/25_algorithms/rotate/constexpr.cc	(nonexistent)
+++ testsuite/25_algorithms/rotate/constexpr.cc	(working copy)
@@ -0,0 +1,41 @@
+//
+// 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/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <algorithm>
+#include <array>
+
+#ifndef __cpp_lib_constexpr_swap_algorithms
+# error "Feature-test macro for constexpr swap algorithms missing"
+#elif __cpp_lib_constexpr_swap_algorithms < 201806L
+# error "Feature-test macro for constexpr swap algorithms has wrong value"
+#endif
+
+constexpr bool
+test()
+{
+  auto ok = true;
+
+  std::array<int, 12> ar0{{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}};
+
+  std::rotate(ar0.begin(), ar0.begin() + 5, ar0.end());
+
+  return ar0[0] == 5 && ar0[5] == 10;
+}
+
+static_assert(test());
Index: testsuite/25_algorithms/sort/constexpr.cc
===================================================================
--- testsuite/25_algorithms/sort/constexpr.cc	(nonexistent)
+++ testsuite/25_algorithms/sort/constexpr.cc	(working copy)
@@ -0,0 +1,46 @@
+// 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/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <algorithm>
+#include <array>
+
+#ifndef __cpp_lib_constexpr_swap_algorithms
+# error "Feature-test macro for constexpr swap algorithms missing"
+#elif __cpp_lib_constexpr_swap_algorithms < 201806L
+# error "Feature-test macro for constexpr swap algorithms has wrong value"
+#endif
+
+constexpr bool
+test()
+{
+  auto ok = true;
+
+  std::array<int, 12> ar0{{10, 0, 1, 2, 5, 6, 7, 8, 3, 4, 9, 11}};
+
+  std::sort(ar0.begin(), ar0.end());
+  ok = ok && std::is_sorted(ar0.begin(), ar0.end());
+
+  std::sort(ar0.begin(), ar0.end(), std::greater<>());
+  ok = ok && std::is_sorted(ar0.begin(), ar0.end(), std::greater<>());
+
+  return ok;
+}
+
+static_assert(test());
Index: testsuite/25_algorithms/sort_heap/constexpr.cc
===================================================================
--- testsuite/25_algorithms/sort_heap/constexpr.cc	(nonexistent)
+++ testsuite/25_algorithms/sort_heap/constexpr.cc	(working copy)
@@ -0,0 +1,56 @@
+// 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/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <algorithm>
+#include <array>
+
+#ifndef __cpp_lib_constexpr_swap_algorithms
+# error "Feature-test macro for constexpr swap algorithms missing"
+#elif __cpp_lib_constexpr_swap_algorithms < 201806L
+# error "Feature-test macro for constexpr swap algorithms has wrong value"
+#endif
+
+constexpr bool
+test()
+{
+  auto ok = true;
+
+  std::array<int, 23>
+  ah{{0,
+      1, 2,
+      3, 4, 5, 6,
+      7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22}};
+
+  std::make_heap(ah.begin(), ah.begin() + 17);
+  ok = ok && std::is_heap(ah.begin(), ah.begin() + 17);
+
+  std::sort_heap(ah.begin(), ah.begin() + 17);
+  ok = ok && std::is_sorted(ah.begin(), ah.begin() + 17);
+
+  std::make_heap(ah.begin(), ah.begin() + 17, std::greater<>());
+  ok = ok && std::is_heap(ah.begin(), ah.begin() + 17, std::greater<>());
+
+  std::sort_heap(ah.begin(), ah.begin() + 17, std::greater<>());
+  ok = ok && std::is_sorted(ah.begin(), ah.begin() + 17, std::greater<>());
+
+  return ok;
+}
+
+static_assert(test());
Index: testsuite/25_algorithms/swap/constexpr.cc
===================================================================
--- testsuite/25_algorithms/swap/constexpr.cc	(nonexistent)
+++ testsuite/25_algorithms/swap/constexpr.cc	(working copy)
@@ -0,0 +1,47 @@
+// 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/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <algorithm>
+
+#ifndef __cpp_lib_constexpr_swap_algorithms
+# error "Feature-test macro for constexpr swap algorithms missing"
+#elif __cpp_lib_constexpr_swap_algorithms < 201806L
+# error "Feature-test macro for constexpr swap algorithms has wrong value"
+#endif
+
+constexpr bool
+test()
+{
+  auto ok = true;
+
+  double asc = 3.1415;
+  double bsc = 2.7182;
+  std::swap(asc, bsc);
+  ok = ok && asc == 2.7182 && bsc == 3.1415;
+
+  float arr[5]{0.0f, 1.0f, 2.0f, 3.0f, 4.0f};
+  float brr[5]{5.0f, 6.0f, 7.0f, 8.0f, 9.0f};
+  std::swap(arr, brr);
+  ok = ok && arr[2] == 7.0f && brr[2] == 2.0f;
+
+  return ok;
+}
+
+static_assert(test());
Index: testsuite/25_algorithms/swap_ranges/constexpr.cc
===================================================================
--- testsuite/25_algorithms/swap_ranges/constexpr.cc	(nonexistent)
+++ testsuite/25_algorithms/swap_ranges/constexpr.cc	(working copy)
@@ -0,0 +1,44 @@
+// 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/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <algorithm>
+#include <array>
+
+#ifndef __cpp_lib_constexpr_swap_algorithms
+# error "Feature-test macro for constexpr swap algorithms missing"
+#elif __cpp_lib_constexpr_swap_algorithms < 201806L
+# error "Feature-test macro for constexpr swap algorithms has wrong value"
+#endif
+
+constexpr bool
+test()
+{
+  auto ok = true;
+
+  std::array<int, 12> ar0{{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}};
+  std::array<int, 12> ar1{{11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}};
+
+  const auto out01 = std::swap_ranges(ar0.begin(), ar0.begin() + 5,
+				      ar1.begin() + 2);
+
+  return ok = ar0[0] == 9 && ar1[2] == 0;
+}
+
+static_assert(test());

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH 2/3] C++20 constexpr lib part 2/3 - swappish functions.
  2019-08-14 15:59                 ` Ed Smith-Rowland via gcc-patches
@ 2019-08-14 16:19                   ` Jonathan Wakely
  0 siblings, 0 replies; 22+ messages in thread
From: Jonathan Wakely @ 2019-08-14 16:19 UTC (permalink / raw)
  To: Ed Smith-Rowland; +Cc: libstdc++, Ville Voutilainen, gcc-patches

On 14/08/19 11:06 -0400, Ed Smith-Rowland wrote:
>I this OK after it passes testing?
>
>Ed
>
>
>

>2019-08-14  Edward Smith-Rowland  <3dw4rd@verizon.net>
>
>	Implement C++20 p0879 - Constexpr for swap and swap related functions.
>	* include/bits/algorithmfwd.h (__cpp_lib_constexpr_swap_algorithms):
>	New macro.
>	* include/std/version: Ditto.

It looks like this line was inserted in the wrong place, as the lines
that follow it are not part of <version>. The entry for
include/std/version should be after include/std/type_traits.


>	(iter_swap, make_heap, next_permutation, partial_sort_copy, pop_heap)
>	(prev_permutation, push_heap, reverse, rotate, sort_heap, swap)
>	(swap_ranges, nth_element, partial_sort, sort): Add constexpr.
>	* include/bits/move.h (swap): Add constexpr.
>	* include/bits/stl_algo.h (__move_median_to_first, __reverse, reverse)
>	(__gcd, __rotate, rotate, __partition, __heap_select)
>	(__partial_sort_copy, partial_sort_copy, __unguarded_partition)
>	(__unguarded_partition_pivot, __partial_sort, __introsort_loop, __sort)
>	(__introselect, __chunk_insertion_sort, next_permutation)
>	(prev_permutation, partition, partial_sort, nth_element, sort)
>	(__iter_swap::iter_swap, iter_swap, swap_ranges): Add constexpr.
>	* include/bits/stl_algobase.h (__iter_swap::iter_swap, iter_swap)
>	(swap_ranges): Add constexpr.
>	* include/bits/stl_heap.h (__push_heap, push_heap, __adjust_heap,
>	__pop_heap, pop_heap, __make_heap, make_heap, __sort_heap, sort_heap):
>	Add constexpr.
>	* include/std/type_traits (swap): Add constexpr.

i.e. here.

OK for trunk with that change if testing passes. Thanks!


^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH 1/3] C++20 constexpr lib part 1/3
  2019-08-06 15:35 Steve Ellcey
  2019-08-06 20:29 ` Jonathan Wakely
@ 2019-08-07 16:10 ` Ed Smith-Rowland via gcc-patches
  1 sibling, 0 replies; 22+ messages in thread
From: Ed Smith-Rowland via gcc-patches @ 2019-08-07 16:10 UTC (permalink / raw)
  To: Steve Ellcey, gcc-patches, libstdc++

On 8/6/19 11:30 AM, Steve Ellcey wrote:
> Ed,
>
> I have run into an ICE that I tracked down to this patch:
>
> commit 02fefffe6b78c4c39169206aa40fb53f367ecba8
> Author: emsr <emsr@138bc75d-0d04-0410-961f-82ee72b054a4>
> Date:   Thu Aug 1 15:25:42 2019 +0000
>
>      2019-08-01  Edward Smith-Rowland  <3dw4rd@verizon.net>
>
>              Implement C++20 p0202 - Add Constexpr Modifiers to Functions
>              in <algorithm> and <utility> Headers.
>              Implement C++20 p1023 - constexpr comparison operators for std::array.
>
>
> Before I try to create a smaller test example (the current failure happens
> when I build https://github.com/llnl/RAJAPerf.git) I was wondering if you
> have already seen this ICE:
>
> /extra/sellcey/raja-build-error/RAJAPerf/src/apps/WIP-COUPLE.cpp: In member function 'virtual void rajaperf::apps::COUPLE::runKernel(rajaperf::VariantID)':
> /extra/sellcey/raja-build-error/RAJAPerf/src/apps/WIP-COUPLE.cpp:217:1: internal compiler error: Segmentation fault
>    217 | } // end namespace rajaperf
>        | ^
> 0xe81ddf crash_signal
> 	../../gcc/gcc/toplev.c:326
> 0x968d14 lookup_page_table_entry
> 	../../gcc/gcc/ggc-page.c:632
> 0x968d14 ggc_set_mark(void const*)
> 	../../gcc/gcc/ggc-page.c:1531
> 0xbfeadf gt_ggc_mx_symtab_node(void*)
> 	/extra/sellcey/gcc-tot/obj-gcc/gcc/gtype-desc.c:1302
> 0xd9d2a7 gt_ggc_ma_order
> 	./gt-passes.h:31
> 0xd9d2a7 gt_ggc_ma_order
> 	./gt-passes.h:26
> 0xb6f49f ggc_mark_root_tab
> 	../../gcc/gcc/ggc-common.c:77
> 0xb6f6c3 ggc_mark_roots()
> 	../../gcc/gcc/ggc-common.c:94
> 0x9696af ggc_collect()
> 	../../gcc/gcc/ggc-page.c:2201
> Please submit a full bug report,
> with preprocessed source if appropriate.
> Please include the complete backtrace with any bug report.
> See <https://gcc.gnu.org/bugs/> for instructions.

I've been building C++14 code (and C++17 and C++20 code) with this patch 
for half a year and no ICE.

I don't see how the patch could impact pre C++20 code.

Ed


^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH 1/3] C++20 constexpr lib part 1/3
  2019-08-06 15:35 Steve Ellcey
@ 2019-08-06 20:29 ` Jonathan Wakely
  2019-08-07 16:10 ` Ed Smith-Rowland via gcc-patches
  1 sibling, 0 replies; 22+ messages in thread
From: Jonathan Wakely @ 2019-08-06 20:29 UTC (permalink / raw)
  To: Steve Ellcey; +Cc: gcc-patches, 3dw4rd, libstdc++

On 06/08/19 15:30 +0000, Steve Ellcey wrote:
>Ed,
>
>I have run into an ICE that I tracked down to this patch:
>
>commit 02fefffe6b78c4c39169206aa40fb53f367ecba8
>Author: emsr <emsr@138bc75d-0d04-0410-961f-82ee72b054a4>
>Date:   Thu Aug 1 15:25:42 2019 +0000
>
>    2019-08-01  Edward Smith-Rowland  <3dw4rd@verizon.net>
>
>            Implement C++20 p0202 - Add Constexpr Modifiers to Functions
>            in <algorithm> and <utility> Headers.
>            Implement C++20 p1023 - constexpr comparison operators for std::array.
>
>
>Before I try to create a smaller test example (the current failure happens
>when I build https://github.com/llnl/RAJAPerf.git) I was wondering if you
>have already seen this ICE:
>
>/extra/sellcey/raja-build-error/RAJAPerf/src/apps/WIP-COUPLE.cpp: In member function 'virtual void rajaperf::apps::COUPLE::runKernel(rajaperf::VariantID)':
>/extra/sellcey/raja-build-error/RAJAPerf/src/apps/WIP-COUPLE.cpp:217:1: internal compiler error: Segmentation fault

The RAJAPerf code appears to be built with -std=gnu++11 which means
Ed's patch should make almost no difference at all. 99% of the patch
has no effect unless compiling with -std=gnu++2a.

I don't see any ICE running the libstdc++ testsuite with -std=gnu++11,
so I have no better suggestion than creating a bugzilla report for the
C++ front-end, with the preprocessed source of WIP-COUPLE.cpp

>  217 | } // end namespace rajaperf
>      | ^
>0xe81ddf crash_signal
>	../../gcc/gcc/toplev.c:326
>0x968d14 lookup_page_table_entry
>	../../gcc/gcc/ggc-page.c:632
>0x968d14 ggc_set_mark(void const*)
>	../../gcc/gcc/ggc-page.c:1531
>0xbfeadf gt_ggc_mx_symtab_node(void*)
>	/extra/sellcey/gcc-tot/obj-gcc/gcc/gtype-desc.c:1302
>0xd9d2a7 gt_ggc_ma_order
>	./gt-passes.h:31
>0xd9d2a7 gt_ggc_ma_order
>	./gt-passes.h:26
>0xb6f49f ggc_mark_root_tab
>	../../gcc/gcc/ggc-common.c:77
>0xb6f6c3 ggc_mark_roots()
>	../../gcc/gcc/ggc-common.c:94
>0x9696af ggc_collect()
>	../../gcc/gcc/ggc-page.c:2201
>Please submit a full bug report,
>with preprocessed source if appropriate.
>Please include the complete backtrace with any bug report.
>See <https://gcc.gnu.org/bugs/> for instructions.

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH 1/3] C++20 constexpr lib part 1/3
@ 2019-08-06 15:35 Steve Ellcey
  2019-08-06 20:29 ` Jonathan Wakely
  2019-08-07 16:10 ` Ed Smith-Rowland via gcc-patches
  0 siblings, 2 replies; 22+ messages in thread
From: Steve Ellcey @ 2019-08-06 15:35 UTC (permalink / raw)
  To: gcc-patches, 3dw4rd, libstdc++

Ed,

I have run into an ICE that I tracked down to this patch:

commit 02fefffe6b78c4c39169206aa40fb53f367ecba8
Author: emsr <emsr@138bc75d-0d04-0410-961f-82ee72b054a4>
Date:   Thu Aug 1 15:25:42 2019 +0000

    2019-08-01  Edward Smith-Rowland  <3dw4rd@verizon.net>

            Implement C++20 p0202 - Add Constexpr Modifiers to Functions
            in <algorithm> and <utility> Headers.
            Implement C++20 p1023 - constexpr comparison operators for std::array.


Before I try to create a smaller test example (the current failure happens
when I build https://github.com/llnl/RAJAPerf.git) I was wondering if you
have already seen this ICE:

/extra/sellcey/raja-build-error/RAJAPerf/src/apps/WIP-COUPLE.cpp: In member function 'virtual void rajaperf::apps::COUPLE::runKernel(rajaperf::VariantID)':
/extra/sellcey/raja-build-error/RAJAPerf/src/apps/WIP-COUPLE.cpp:217:1: internal compiler error: Segmentation fault
  217 | } // end namespace rajaperf
      | ^
0xe81ddf crash_signal
	../../gcc/gcc/toplev.c:326
0x968d14 lookup_page_table_entry
	../../gcc/gcc/ggc-page.c:632
0x968d14 ggc_set_mark(void const*)
	../../gcc/gcc/ggc-page.c:1531
0xbfeadf gt_ggc_mx_symtab_node(void*)
	/extra/sellcey/gcc-tot/obj-gcc/gcc/gtype-desc.c:1302
0xd9d2a7 gt_ggc_ma_order
	./gt-passes.h:31
0xd9d2a7 gt_ggc_ma_order
	./gt-passes.h:26
0xb6f49f ggc_mark_root_tab
	../../gcc/gcc/ggc-common.c:77
0xb6f6c3 ggc_mark_roots()
	../../gcc/gcc/ggc-common.c:94
0x9696af ggc_collect()
	../../gcc/gcc/ggc-page.c:2201
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.

^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2019-08-14 16:02 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-26 23:13 [PATCH 1/3] C++20 constexpr lib part 1/3 Ed Smith-Rowland via gcc-patches
2019-06-27 15:41 ` Jonathan Wakely
2019-06-27 16:54   ` Ed Smith-Rowland via gcc-patches
2019-06-27 17:06     ` Ville Voutilainen
2019-06-27 23:07       ` Ed Smith-Rowland via gcc-patches
2019-06-27 23:31         ` Jonathan Wakely
2019-07-02 12:11 ` Jonathan Wakely
2019-07-06  7:55   ` Ed Smith-Rowland via gcc-patches
2019-07-06  8:01     ` Ville Voutilainen
2019-07-11 16:48       ` Ed Smith-Rowland via gcc-patches
2019-07-31 15:00       ` Ed Smith-Rowland via gcc-patches
2019-08-01 10:56         ` Jonathan Wakely
2019-08-01 15:47           ` Ed Smith-Rowland via gcc-patches
2019-08-01 17:16             ` [PATCH 2/3] C++20 constexpr lib part 2/3 - swappish functions Ed Smith-Rowland via gcc-patches
2019-08-13 11:24               ` Jonathan Wakely
2019-08-14 15:59                 ` Ed Smith-Rowland via gcc-patches
2019-08-14 16:19                   ` Jonathan Wakely
2019-08-01 19:45             ` [PATCH 1/3] C++20 constexpr lib part 1/3 Jonathan Wakely
2019-08-02  1:04               ` Ed Smith-Rowland via gcc-patches
2019-08-06 15:35 Steve Ellcey
2019-08-06 20:29 ` Jonathan Wakely
2019-08-07 16:10 ` Ed Smith-Rowland via gcc-patches

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).