Bug 60271 - [DR2369] [C++1y] std::max(initializer_list<T>) cannot use std::max_element
Summary: [DR2369] [C++1y] std::max(initializer_list<T>) cannot use std::max_element
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 4.9.0
: P3 normal
Target Milestone: 5.0
Assignee: Jonathan Wakely
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-02-19 10:44 UTC by Jonathan Wakely
Modified: 2015-09-02 11:13 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2014-12-21 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Wakely 2014-02-19 10:44:47 UTC
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n3893.html#2350 (approved in Issaquah) adds constexpr to std::max(initializer_list<T>), which means we can't use std::max_element to implement it.
Comment 1 Marc Glisse 2014-02-20 14:36:03 UTC
In my opinion, the sensible thing to do is add constexpr to max_element (and the __ops helpers) once the front-end supports it, not duplicate the code in max(initializer_list). Well, since max_element is just one line calling __max_element, there isn't that much code duplicated, but on the principle...

Did you file an LWG issue about this?
Comment 2 Jonathan Wakely 2014-02-20 14:44:25 UTC
The same thought occurred to me, but I didn't file an issue.
Comment 3 Jonathan Wakely 2014-02-20 15:00:47 UTC
Even if max_element() isn't made constexpr, we can make __max_element constexpr (once the FE supports it) and use it directly in max.

It's certainly solvable, I just wanted to create this PR so we don't forget about it.
Comment 4 Marc Glisse 2014-02-20 16:29:43 UTC
(In reply to Jonathan Wakely from comment #2)
> The same thought occurred to me, but I didn't file an issue.

Should I do it, or are you going to?

(In reply to Jonathan Wakely from comment #3)
> It's certainly solvable, I just wanted to create this PR so we don't forget
> about it.

That's how I took it, thanks :-)
Comment 5 Jonathan Wakely 2014-02-20 18:15:56 UTC
(In reply to Marc Glisse from comment #4)
> (In reply to Jonathan Wakely from comment #2)
> > The same thought occurred to me, but I didn't file an issue.
> 
> Should I do it, or are you going to?

Please go ahead, I might not get a chance until next week now!
Comment 6 Jonathan Wakely 2014-12-22 15:02:45 UTC
http://cplusplus.github.io/LWG/lwg-active.html#2369
Comment 7 Jonathan Wakely 2014-12-22 16:00:49 UTC
Author: redi
Date: Mon Dec 22 16:00:16 2014
New Revision: 219015

URL: https://gcc.gnu.org/viewcvs?rev=219015&root=gcc&view=rev
Log:
2014-12-22  Ville Voutilainen  <ville.voutilainen@gmail.com>

	PR libstdc++/60271
	C++14 constexpr min, max, minmax, min_element, max_element
	and minmax_element. Also constexpr for 20.9.5-20.9.9,
	aka various library functors.
	* include/bits/c++config: Add _GLIBCXX14_CONSTEXPR.
	* include/bits/algorithmfwd.h (min, max, minmax, min_element,
	max_element): Use it.
	* include/bits/predefined_ops.h (_Iter_less_iter, __iter_less_iter,
	_Iter_comp_iter, __iter_comp_iter): Likewise.
	* include/bits/stl_algo.h (minmax, __minmax_element, minmax_element,
	min, max, __min_element, min_element, __max_element, max_element)
	Likewise.
	* include/bits/stl_algobase.h (min, max): Likewise.
	* include/bits/stl_function.h (plus, minus, multiplies, divides,
	modulus, negate, equal_to, not_equal_to, greater, less, greater_equal,
	less_equal, logical_and, logical_or, logical_not, bit_and, bit_or,
	bit_xor, bit_not, unary_negate, not1, binary_negate, not2): Likewise.
	* testsuite/20_util/function_objects/constexpr.cc: New.
	* testsuite/25_algorithms/max/constexpr.cc: Likewise.
	* testsuite/25_algorithms/max_element/constexpr.cc: Likewise.
	* testsuite/25_algorithms/min/constexpr.cc: Likewise.
	* testsuite/25_algorithms/min_element/constexpr.cc: Likewise.
	* testsuite/25_algorithms/minmax/constexpr.cc: Likewise.
	* testsuite/25_algorithms/minmax_element/constexpr.cc: Likewise.
	* testsuite/ext/profile/mutex_extensions_neg.cc: Adjust dg-error.

Added:
    trunk/libstdc++-v3/testsuite/20_util/function_objects/constexpr.cc
    trunk/libstdc++-v3/testsuite/25_algorithms/max/constexpr.cc
      - copied, changed from r219014, trunk/libstdc++-v3/testsuite/ext/profile/mutex_extensions_neg.cc
    trunk/libstdc++-v3/testsuite/25_algorithms/max_element/constexpr.cc
      - copied, changed from r219014, trunk/libstdc++-v3/testsuite/ext/profile/mutex_extensions_neg.cc
    trunk/libstdc++-v3/testsuite/25_algorithms/min/constexpr.cc
      - copied, changed from r219014, trunk/libstdc++-v3/testsuite/ext/profile/mutex_extensions_neg.cc
    trunk/libstdc++-v3/testsuite/25_algorithms/min_element/constexpr.cc
      - copied, changed from r219014, trunk/libstdc++-v3/testsuite/ext/profile/mutex_extensions_neg.cc
    trunk/libstdc++-v3/testsuite/25_algorithms/minmax/constexpr.cc
      - copied, changed from r219014, trunk/libstdc++-v3/testsuite/ext/profile/mutex_extensions_neg.cc
    trunk/libstdc++-v3/testsuite/25_algorithms/minmax_element/constexpr.cc
      - copied, changed from r219014, trunk/libstdc++-v3/testsuite/ext/profile/mutex_extensions_neg.cc
Modified:
    trunk/libstdc++-v3/ChangeLog
    trunk/libstdc++-v3/include/bits/algorithmfwd.h
    trunk/libstdc++-v3/include/bits/c++config
    trunk/libstdc++-v3/include/bits/predefined_ops.h
    trunk/libstdc++-v3/include/bits/stl_algo.h
    trunk/libstdc++-v3/include/bits/stl_algobase.h
    trunk/libstdc++-v3/include/bits/stl_function.h
    trunk/libstdc++-v3/testsuite/ext/profile/mutex_extensions_neg.cc
Comment 8 Jonathan Wakely 2014-12-22 16:43:06 UTC
Suspending until the DR is resolved.
Comment 9 Jakub Jelinek 2015-04-22 11:59:00 UTC
GCC 5.1 has been released.
Comment 10 Richard Biener 2015-07-16 09:11:26 UTC
GCC 5.2 is being released, adjusting target milestone to 5.3.
Comment 11 Jonathan Wakely 2015-09-02 11:13:21 UTC
The issue is resolved and the code was fixed for 5.1