From 8dff34fe8e008344876bfc299203381000b5d6f7 Mon Sep 17 00:00:00 2001 From: Ville Voutilainen Date: Mon, 22 Dec 2014 18:00:16 +0200 Subject: [PATCH] re PR libstdc++/60271 ([DR2369] [C++1y] std::max(initializer_list) cannot use std::max_element) 2014-12-22 Ville Voutilainen 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. From-SVN: r219015 --- libstdc++-v3/ChangeLog | 28 +++++++ libstdc++-v3/include/bits/algorithmfwd.h | 18 +++++ libstdc++-v3/include/bits/c++config | 8 ++ libstdc++-v3/include/bits/predefined_ops.h | 7 +- libstdc++-v3/include/bits/stl_algo.h | 19 ++++- libstdc++-v3/include/bits/stl_algobase.h | 4 + libstdc++-v3/include/bits/stl_function.h | 44 +++++++++++ .../20_util/function_objects/constexpr.cc | 77 +++++++++++++++++++ .../testsuite/25_algorithms/max/constexpr.cc | 28 +++++++ .../25_algorithms/max_element/constexpr.cc | 29 +++++++ .../testsuite/25_algorithms/min/constexpr.cc | 28 +++++++ .../25_algorithms/min_element/constexpr.cc | 29 +++++++ .../25_algorithms/minmax/constexpr.cc | 32 ++++++++ .../25_algorithms/minmax_element/constexpr.cc | 33 ++++++++ .../ext/profile/mutex_extensions_neg.cc | 2 +- 15 files changed, 382 insertions(+), 4 deletions(-) create mode 100644 libstdc++-v3/testsuite/20_util/function_objects/constexpr.cc create mode 100644 libstdc++-v3/testsuite/25_algorithms/max/constexpr.cc create mode 100644 libstdc++-v3/testsuite/25_algorithms/max_element/constexpr.cc create mode 100644 libstdc++-v3/testsuite/25_algorithms/min/constexpr.cc create mode 100644 libstdc++-v3/testsuite/25_algorithms/min_element/constexpr.cc create mode 100644 libstdc++-v3/testsuite/25_algorithms/minmax/constexpr.cc create mode 100644 libstdc++-v3/testsuite/25_algorithms/minmax_element/constexpr.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 8a201eb8572..4fe8283f96b 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,31 @@ +2014-12-22 Ville Voutilainen + + 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. + 2014-12-22 Jonathan Wakely * doc/xml/manual/status_cxx2011.xml: Update. diff --git a/libstdc++-v3/include/bits/algorithmfwd.h b/libstdc++-v3/include/bits/algorithmfwd.h index aee1eec5b6b..b45828eb3d2 100644 --- a/libstdc++-v3/include/bits/algorithmfwd.h +++ b/libstdc++-v3/include/bits/algorithmfwd.h @@ -352,10 +352,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION make_heap(_RAIter, _RAIter, _Compare); template + _GLIBCXX14_CONSTEXPR const _Tp& max(const _Tp&, const _Tp&); template + _GLIBCXX14_CONSTEXPR const _Tp& max(const _Tp&, const _Tp&, _Compare); @@ -363,10 +365,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // merge template + _GLIBCXX14_CONSTEXPR const _Tp& min(const _Tp&, const _Tp&); template + _GLIBCXX14_CONSTEXPR const _Tp& min(const _Tp&, const _Tp&, _Compare); @@ -374,42 +378,52 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #if __cplusplus >= 201103L template + _GLIBCXX14_CONSTEXPR pair minmax(const _Tp&, const _Tp&); template + _GLIBCXX14_CONSTEXPR pair minmax(const _Tp&, const _Tp&, _Compare); template + _GLIBCXX14_CONSTEXPR pair<_FIter, _FIter> minmax_element(_FIter, _FIter); template + _GLIBCXX14_CONSTEXPR pair<_FIter, _FIter> minmax_element(_FIter, _FIter, _Compare); template + _GLIBCXX14_CONSTEXPR _Tp min(initializer_list<_Tp>); template + _GLIBCXX14_CONSTEXPR _Tp min(initializer_list<_Tp>, _Compare); template + _GLIBCXX14_CONSTEXPR _Tp max(initializer_list<_Tp>); template + _GLIBCXX14_CONSTEXPR _Tp max(initializer_list<_Tp>, _Compare); template + _GLIBCXX14_CONSTEXPR pair<_Tp, _Tp> minmax(initializer_list<_Tp>); template + _GLIBCXX14_CONSTEXPR pair<_Tp, _Tp> minmax(initializer_list<_Tp>, _Compare); #endif @@ -655,10 +669,12 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO lexicographical_compare(_IIter1, _IIter1, _IIter2, _IIter2, _Compare); template + _GLIBCXX14_CONSTEXPR _FIter max_element(_FIter, _FIter); template + _GLIBCXX14_CONSTEXPR _FIter max_element(_FIter, _FIter, _Compare); @@ -672,10 +688,12 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO merge(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, _Compare); template + _GLIBCXX14_CONSTEXPR _FIter min_element(_FIter, _FIter); template + _GLIBCXX14_CONSTEXPR _FIter min_element(_FIter, _FIter, _Compare); diff --git a/libstdc++-v3/include/bits/c++config b/libstdc++-v3/include/bits/c++config index ec7414dfd27..356a526a0ba 100644 --- a/libstdc++-v3/include/bits/c++config +++ b/libstdc++-v3/include/bits/c++config @@ -103,6 +103,14 @@ # endif #endif +#ifndef _GLIBCXX14_CONSTEXPR +# if __cplusplus >= 201402L +# define _GLIBCXX14_CONSTEXPR constexpr +# else +# define _GLIBCXX14_CONSTEXPR +# endif +#endif + // Macro for noexcept, to support in mixed 03/0x mode. #ifndef _GLIBCXX_NOEXCEPT # if __cplusplus >= 201103L diff --git a/libstdc++-v3/include/bits/predefined_ops.h b/libstdc++-v3/include/bits/predefined_ops.h index 78f5e37d7b4..e31d8c38912 100644 --- a/libstdc++-v3/include/bits/predefined_ops.h +++ b/libstdc++-v3/include/bits/predefined_ops.h @@ -37,11 +37,12 @@ namespace __ops struct _Iter_less_iter { template + _GLIBCXX14_CONSTEXPR bool operator()(_Iterator1 __it1, _Iterator2 __it2) const { return *__it1 < *__it2; } }; - + _GLIBCXX14_CONSTEXPR inline _Iter_less_iter __iter_less_iter() { return _Iter_less_iter(); } @@ -110,18 +111,20 @@ namespace __ops struct _Iter_comp_iter { _Compare _M_comp; - + _GLIBCXX14_CONSTEXPR _Iter_comp_iter(_Compare __comp) : _M_comp(__comp) { } template + _GLIBCXX14_CONSTEXPR bool operator()(_Iterator1 __it1, _Iterator2 __it2) { return bool(_M_comp(*__it1, *__it2)); } }; template + _GLIBCXX14_CONSTEXPR inline _Iter_comp_iter<_Compare> __iter_comp_iter(_Compare __comp) { return _Iter_comp_iter<_Compare>(__comp); } diff --git a/libstdc++-v3/include/bits/stl_algo.h b/libstdc++-v3/include/bits/stl_algo.h index 0ce73c1bbb3..dfbb9faecfd 100644 --- a/libstdc++-v3/include/bits/stl_algo.h +++ b/libstdc++-v3/include/bits/stl_algo.h @@ -3271,6 +3271,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * __b) otherwise. */ template + _GLIBCXX14_CONSTEXPR inline pair minmax(const _Tp& __a, const _Tp& __b) { @@ -3291,6 +3292,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * __b) otherwise. */ template + _GLIBCXX14_CONSTEXPR inline pair minmax(const _Tp& __a, const _Tp& __b, _Compare __comp) { @@ -3299,6 +3301,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template + _GLIBCXX14_CONSTEXPR pair<_ForwardIterator, _ForwardIterator> __minmax_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) @@ -3308,7 +3311,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION || ++__next == __last) return std::make_pair(__first, __first); - _ForwardIterator __min, __max; + _ForwardIterator __min{}, __max{}; if (__comp(__next, __first)) { __min = __next; @@ -3369,6 +3372,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * such that no other element in the range is larger. */ template + _GLIBCXX14_CONSTEXPR inline pair<_ForwardIterator, _ForwardIterator> minmax_element(_ForwardIterator __first, _ForwardIterator __last) { @@ -3395,6 +3399,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * such that no other element in the range is larger. */ template + _GLIBCXX14_CONSTEXPR inline pair<_ForwardIterator, _ForwardIterator> minmax_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) @@ -3412,26 +3417,31 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // N2722 + DR 915. template + _GLIBCXX14_CONSTEXPR inline _Tp min(initializer_list<_Tp> __l) { return *std::min_element(__l.begin(), __l.end()); } template + _GLIBCXX14_CONSTEXPR inline _Tp min(initializer_list<_Tp> __l, _Compare __comp) { return *std::min_element(__l.begin(), __l.end(), __comp); } template + _GLIBCXX14_CONSTEXPR inline _Tp max(initializer_list<_Tp> __l) { return *std::max_element(__l.begin(), __l.end()); } template + _GLIBCXX14_CONSTEXPR inline _Tp max(initializer_list<_Tp> __l, _Compare __comp) { return *std::max_element(__l.begin(), __l.end(), __comp); } template + _GLIBCXX14_CONSTEXPR inline pair<_Tp, _Tp> minmax(initializer_list<_Tp> __l) { @@ -3441,6 +3451,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template + _GLIBCXX14_CONSTEXPR inline pair<_Tp, _Tp> minmax(initializer_list<_Tp> __l, _Compare __comp) { @@ -5381,6 +5392,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO } template + _GLIBCXX14_CONSTEXPR _ForwardIterator __min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) @@ -5402,6 +5414,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO * @return Iterator referencing the first instance of the smallest value. */ template + _GLIBCXX14_CONSTEXPR _ForwardIterator inline min_element(_ForwardIterator __first, _ForwardIterator __last) { @@ -5425,6 +5438,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO * according to __comp. */ template + _GLIBCXX14_CONSTEXPR inline _ForwardIterator min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) @@ -5441,6 +5455,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO } template + _GLIBCXX14_CONSTEXPR _ForwardIterator __max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) @@ -5461,6 +5476,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO * @return Iterator referencing the first instance of the largest value. */ template + _GLIBCXX14_CONSTEXPR inline _ForwardIterator max_element(_ForwardIterator __first, _ForwardIterator __last) { @@ -5484,6 +5500,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO * according to __comp. */ template + _GLIBCXX14_CONSTEXPR inline _ForwardIterator max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) diff --git a/libstdc++-v3/include/bits/stl_algobase.h b/libstdc++-v3/include/bits/stl_algobase.h index f7c11e931d7..15ee8200d2a 100644 --- a/libstdc++-v3/include/bits/stl_algobase.h +++ b/libstdc++-v3/include/bits/stl_algobase.h @@ -190,6 +190,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * preprocessor macro. */ template + _GLIBCXX14_CONSTEXPR inline const _Tp& min(const _Tp& __a, const _Tp& __b) { @@ -213,6 +214,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * preprocessor macro. */ template + _GLIBCXX14_CONSTEXPR inline const _Tp& max(const _Tp& __a, const _Tp& __b) { @@ -236,6 +238,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * once, unlike a preprocessor macro. */ template + _GLIBCXX14_CONSTEXPR inline const _Tp& min(const _Tp& __a, const _Tp& __b, _Compare __comp) { @@ -257,6 +260,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * once, unlike a preprocessor macro. */ template + _GLIBCXX14_CONSTEXPR inline const _Tp& max(const _Tp& __a, const _Tp& __b, _Compare __comp) { diff --git a/libstdc++-v3/include/bits/stl_function.h b/libstdc++-v3/include/bits/stl_function.h index 71215b879e5..79f79594cc9 100644 --- a/libstdc++-v3/include/bits/stl_function.h +++ b/libstdc++-v3/include/bits/stl_function.h @@ -166,6 +166,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct plus : public binary_function<_Tp, _Tp, _Tp> { + _GLIBCXX14_CONSTEXPR _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x + __y; } @@ -175,6 +176,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct minus : public binary_function<_Tp, _Tp, _Tp> { + _GLIBCXX14_CONSTEXPR _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x - __y; } @@ -184,6 +186,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct multiplies : public binary_function<_Tp, _Tp, _Tp> { + _GLIBCXX14_CONSTEXPR _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x * __y; } @@ -193,6 +196,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct divides : public binary_function<_Tp, _Tp, _Tp> { + _GLIBCXX14_CONSTEXPR _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x / __y; } @@ -202,6 +206,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct modulus : public binary_function<_Tp, _Tp, _Tp> { + _GLIBCXX14_CONSTEXPR _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x % __y; } @@ -211,6 +216,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct negate : public unary_function<_Tp, _Tp> { + _GLIBCXX14_CONSTEXPR _Tp operator()(const _Tp& __x) const { return -__x; } @@ -225,6 +231,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct plus { template + _GLIBCXX14_CONSTEXPR auto operator()(_Tp&& __t, _Up&& __u) const noexcept(noexcept(std::forward<_Tp>(__t) + std::forward<_Up>(__u))) @@ -239,6 +246,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct minus { template + _GLIBCXX14_CONSTEXPR auto operator()(_Tp&& __t, _Up&& __u) const noexcept(noexcept(std::forward<_Tp>(__t) - std::forward<_Up>(__u))) @@ -253,6 +261,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct multiplies { template + _GLIBCXX14_CONSTEXPR auto operator()(_Tp&& __t, _Up&& __u) const noexcept(noexcept(std::forward<_Tp>(__t) * std::forward<_Up>(__u))) @@ -267,6 +276,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct divides { template + _GLIBCXX14_CONSTEXPR auto operator()(_Tp&& __t, _Up&& __u) const noexcept(noexcept(std::forward<_Tp>(__t) / std::forward<_Up>(__u))) @@ -281,6 +291,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct modulus { template + _GLIBCXX14_CONSTEXPR auto operator()(_Tp&& __t, _Up&& __u) const noexcept(noexcept(std::forward<_Tp>(__t) % std::forward<_Up>(__u))) @@ -295,6 +306,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct negate { template + _GLIBCXX14_CONSTEXPR auto operator()(_Tp&& __t) const noexcept(noexcept(-std::forward<_Tp>(__t))) @@ -339,6 +351,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct equal_to : public binary_function<_Tp, _Tp, bool> { + _GLIBCXX14_CONSTEXPR bool operator()(const _Tp& __x, const _Tp& __y) const { return __x == __y; } @@ -348,6 +361,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct not_equal_to : public binary_function<_Tp, _Tp, bool> { + _GLIBCXX14_CONSTEXPR bool operator()(const _Tp& __x, const _Tp& __y) const { return __x != __y; } @@ -357,6 +371,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct greater : public binary_function<_Tp, _Tp, bool> { + _GLIBCXX14_CONSTEXPR bool operator()(const _Tp& __x, const _Tp& __y) const { return __x > __y; } @@ -366,6 +381,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct less : public binary_function<_Tp, _Tp, bool> { + _GLIBCXX14_CONSTEXPR bool operator()(const _Tp& __x, const _Tp& __y) const { return __x < __y; } @@ -375,6 +391,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct greater_equal : public binary_function<_Tp, _Tp, bool> { + _GLIBCXX14_CONSTEXPR bool operator()(const _Tp& __x, const _Tp& __y) const { return __x >= __y; } @@ -384,6 +401,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct less_equal : public binary_function<_Tp, _Tp, bool> { + _GLIBCXX14_CONSTEXPR bool operator()(const _Tp& __x, const _Tp& __y) const { return __x <= __y; } @@ -395,6 +413,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct equal_to { template + _GLIBCXX14_CONSTEXPR auto operator()(_Tp&& __t, _Up&& __u) const noexcept(noexcept(std::forward<_Tp>(__t) == std::forward<_Up>(__u))) @@ -409,6 +428,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct not_equal_to { template + _GLIBCXX14_CONSTEXPR auto operator()(_Tp&& __t, _Up&& __u) const noexcept(noexcept(std::forward<_Tp>(__t) != std::forward<_Up>(__u))) @@ -423,6 +443,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct greater { template + _GLIBCXX14_CONSTEXPR auto operator()(_Tp&& __t, _Up&& __u) const noexcept(noexcept(std::forward<_Tp>(__t) > std::forward<_Up>(__u))) @@ -437,6 +458,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct less { template + _GLIBCXX14_CONSTEXPR auto operator()(_Tp&& __t, _Up&& __u) const noexcept(noexcept(std::forward<_Tp>(__t) < std::forward<_Up>(__u))) @@ -451,6 +473,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct greater_equal { template + _GLIBCXX14_CONSTEXPR auto operator()(_Tp&& __t, _Up&& __u) const noexcept(noexcept(std::forward<_Tp>(__t) >= std::forward<_Up>(__u))) @@ -465,6 +488,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct less_equal { template + _GLIBCXX14_CONSTEXPR auto operator()(_Tp&& __t, _Up&& __u) const noexcept(noexcept(std::forward<_Tp>(__t) <= std::forward<_Up>(__u))) @@ -500,6 +524,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct logical_and : public binary_function<_Tp, _Tp, bool> { + _GLIBCXX14_CONSTEXPR bool operator()(const _Tp& __x, const _Tp& __y) const { return __x && __y; } @@ -509,6 +534,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct logical_or : public binary_function<_Tp, _Tp, bool> { + _GLIBCXX14_CONSTEXPR bool operator()(const _Tp& __x, const _Tp& __y) const { return __x || __y; } @@ -518,6 +544,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct logical_not : public unary_function<_Tp, bool> { + _GLIBCXX14_CONSTEXPR bool operator()(const _Tp& __x) const { return !__x; } @@ -529,6 +556,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct logical_and { template + _GLIBCXX14_CONSTEXPR auto operator()(_Tp&& __t, _Up&& __u) const noexcept(noexcept(std::forward<_Tp>(__t) && std::forward<_Up>(__u))) @@ -543,6 +571,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct logical_or { template + _GLIBCXX14_CONSTEXPR auto operator()(_Tp&& __t, _Up&& __u) const noexcept(noexcept(std::forward<_Tp>(__t) || std::forward<_Up>(__u))) @@ -557,6 +586,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct logical_not { template + _GLIBCXX14_CONSTEXPR auto operator()(_Tp&& __t) const noexcept(noexcept(!std::forward<_Tp>(__t))) @@ -587,6 +617,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct bit_and : public binary_function<_Tp, _Tp, _Tp> { + _GLIBCXX14_CONSTEXPR _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x & __y; } @@ -595,6 +626,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct bit_or : public binary_function<_Tp, _Tp, _Tp> { + _GLIBCXX14_CONSTEXPR _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x | __y; } @@ -603,6 +635,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct bit_xor : public binary_function<_Tp, _Tp, _Tp> { + _GLIBCXX14_CONSTEXPR _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x ^ __y; } @@ -611,6 +644,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct bit_not : public unary_function<_Tp, _Tp> { + _GLIBCXX14_CONSTEXPR _Tp operator()(const _Tp& __x) const { return ~__x; } @@ -621,6 +655,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct bit_and { template + _GLIBCXX14_CONSTEXPR auto operator()(_Tp&& __t, _Up&& __u) const noexcept(noexcept(std::forward<_Tp>(__t) & std::forward<_Up>(__u))) @@ -634,6 +669,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct bit_or { template + _GLIBCXX14_CONSTEXPR auto operator()(_Tp&& __t, _Up&& __u) const noexcept(noexcept(std::forward<_Tp>(__t) | std::forward<_Up>(__u))) @@ -647,6 +683,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct bit_xor { template + _GLIBCXX14_CONSTEXPR auto operator()(_Tp&& __t, _Up&& __u) const noexcept(noexcept(std::forward<_Tp>(__t) ^ std::forward<_Up>(__u))) @@ -660,6 +697,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct bit_not { template + _GLIBCXX14_CONSTEXPR auto operator()(_Tp&& __t) const noexcept(noexcept(~std::forward<_Tp>(__t))) @@ -708,9 +746,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _Predicate _M_pred; public: + _GLIBCXX14_CONSTEXPR explicit unary_negate(const _Predicate& __x) : _M_pred(__x) { } + _GLIBCXX14_CONSTEXPR bool operator()(const typename _Predicate::argument_type& __x) const { return !_M_pred(__x); } @@ -718,6 +758,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// One of the @link negators negation functors@endlink. template + _GLIBCXX14_CONSTEXPR inline unary_negate<_Predicate> not1(const _Predicate& __pred) { return unary_negate<_Predicate>(__pred); } @@ -732,9 +773,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _Predicate _M_pred; public: + _GLIBCXX14_CONSTEXPR explicit binary_negate(const _Predicate& __x) : _M_pred(__x) { } + _GLIBCXX14_CONSTEXPR bool operator()(const typename _Predicate::first_argument_type& __x, const typename _Predicate::second_argument_type& __y) const @@ -743,6 +786,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// One of the @link negators negation functors@endlink. template + _GLIBCXX14_CONSTEXPR inline binary_negate<_Predicate> not2(const _Predicate& __pred) { return binary_negate<_Predicate>(__pred); } diff --git a/libstdc++-v3/testsuite/20_util/function_objects/constexpr.cc b/libstdc++-v3/testsuite/20_util/function_objects/constexpr.cc new file mode 100644 index 00000000000..3ad7e0dbee4 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/function_objects/constexpr.cc @@ -0,0 +1,77 @@ +// { dg-options "-std=gnu++14" } +// { dg-do compile } + +// Copyright (C) 2014 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 +// . + +// 20.9.5-20.9.9 + +#include + +static_assert(std::plus()(1,2)==3, ""); +static_assert(std::minus()(3,2)==1, ""); +static_assert(std::multiplies()(3,2)==6, ""); +static_assert(std::divides()(6,2)==3, ""); +static_assert(std::modulus()(7,2)==1, ""); +static_assert(std::negate()(-5)==5, ""); + +static_assert(std::plus()(1,2)==3, ""); +static_assert(std::minus()(3,2)==1, ""); +static_assert(std::multiplies()(3,2)==6, ""); +static_assert(std::divides()(6,2)==3, ""); +static_assert(std::modulus()(7,2)==1, ""); +static_assert(std::negate()(-5)==5, ""); + +static_assert(std::equal_to()(2,2), ""); +static_assert(std::not_equal_to()(1,2), ""); +static_assert(std::greater()(2,1), ""); +static_assert(std::less()(1,2), ""); +static_assert(std::greater_equal()(2,2), ""); +static_assert(std::less_equal()(2,2), ""); + +static_assert(std::equal_to()(2,2), ""); +static_assert(std::not_equal_to()(1,2), ""); +static_assert(std::greater()(2,1), ""); +static_assert(std::less()(1,2), ""); +static_assert(std::greater_equal()(2,2), ""); +static_assert(std::less_equal()(2,2), ""); + +static_assert(std::logical_and()(1,1), ""); +static_assert(std::logical_or()(0,1), ""); +static_assert(std::logical_not()(0), ""); + +static_assert(std::logical_and()(1,1), ""); +static_assert(std::logical_or()(0,1), ""); +static_assert(std::logical_not()(0), ""); + +static_assert(std::bit_and()(3,2)==2, ""); +static_assert(std::bit_or()(1,2)==3, ""); +static_assert(std::bit_xor()(1,1)==0, ""); +static_assert(std::bit_not()(std::bit_not()(0))==0, ""); + +static_assert(std::bit_and()(3,2)==2, ""); +static_assert(std::bit_or()(1,2)==3, ""); +static_assert(std::bit_xor()(1,1)==0, ""); +static_assert(std::bit_not()(std::bit_not()(0))==0, ""); + +static_assert(std::unary_negate> + (std::logical_not())(1), ""); +static_assert(std::not1(std::logical_not())(1), ""); + +static_assert(std::binary_negate> + (std::logical_and())(0,0), ""); +static_assert(std::not2(std::logical_and())(0,0), ""); diff --git a/libstdc++-v3/testsuite/25_algorithms/max/constexpr.cc b/libstdc++-v3/testsuite/25_algorithms/max/constexpr.cc new file mode 100644 index 00000000000..3db6d8f1054 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/max/constexpr.cc @@ -0,0 +1,28 @@ +// { dg-options "-std=gnu++14" } +// { dg-do compile } + +// Copyright (C) 2014 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 +// . + +#include +#include + +static_assert(std::max(1, 2) == 2, ""); +static_assert(std::max(2, 1, std::greater()) == 1, ""); +static_assert(std::max({1, 2}) == 2, ""); +static_assert(std::max({2, 1}, std::greater())==1, ""); + diff --git a/libstdc++-v3/testsuite/25_algorithms/max_element/constexpr.cc b/libstdc++-v3/testsuite/25_algorithms/max_element/constexpr.cc new file mode 100644 index 00000000000..666dad875dd --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/max_element/constexpr.cc @@ -0,0 +1,29 @@ +// { dg-options "-std=gnu++14" } +// { dg-do compile } + +// Copyright (C) 2014 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 +// . + +#include +#include +#include + +constexpr std::initializer_list test{1, 2}; + +static_assert(*std::max_element(test.begin(), test.end()) == 2, ""); +static_assert(*std::max_element(test.begin(), test.end(), + std::greater()) == 1, ""); diff --git a/libstdc++-v3/testsuite/25_algorithms/min/constexpr.cc b/libstdc++-v3/testsuite/25_algorithms/min/constexpr.cc new file mode 100644 index 00000000000..615b18c8b03 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/min/constexpr.cc @@ -0,0 +1,28 @@ +// { dg-options "-std=gnu++14" } +// { dg-do compile } + +// Copyright (C) 2014 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 +// . + +#include +#include + +static_assert(std::min(2, 1) == 1, ""); +static_assert(std::min(2, 1, std::greater()) == 2, ""); +static_assert(std::min({2, 1}) == 1, ""); +static_assert(std::min({1, 2}, std::greater())==2, ""); + diff --git a/libstdc++-v3/testsuite/25_algorithms/min_element/constexpr.cc b/libstdc++-v3/testsuite/25_algorithms/min_element/constexpr.cc new file mode 100644 index 00000000000..376be83542d --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/min_element/constexpr.cc @@ -0,0 +1,29 @@ +// { dg-options "-std=gnu++14" } +// { dg-do compile } + +// Copyright (C) 2014 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 +// . + +#include +#include +#include + +constexpr std::initializer_list test{2, 1}; + +static_assert(*std::min_element(test.begin(), test.end()) == 1, ""); +static_assert(*std::min_element(test.begin(), test.end(), + std::greater()) == 2, ""); diff --git a/libstdc++-v3/testsuite/25_algorithms/minmax/constexpr.cc b/libstdc++-v3/testsuite/25_algorithms/minmax/constexpr.cc new file mode 100644 index 00000000000..cd5d95ee713 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/minmax/constexpr.cc @@ -0,0 +1,32 @@ +// { dg-options "-std=gnu++14" } +// { dg-do compile } + +// Copyright (C) 2014 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 +// . + +#include +#include +#include + +static_assert(std::minmax(2, 1) == + std::pair(1, 2), ""); +static_assert(std::minmax(2, 1, std::greater()) == + std::pair(2, 1), ""); +static_assert(std::minmax({2, 1}) == + std::pair(1, 2), ""); +static_assert(std::minmax({2, 1}, std::greater())== + std::pair(2, 1), ""); diff --git a/libstdc++-v3/testsuite/25_algorithms/minmax_element/constexpr.cc b/libstdc++-v3/testsuite/25_algorithms/minmax_element/constexpr.cc new file mode 100644 index 00000000000..9a79bc1259d --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/minmax_element/constexpr.cc @@ -0,0 +1,33 @@ +// { dg-options "-std=gnu++14" } +// { dg-do compile } + +// Copyright (C) 2014 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 +// . + +#include +#include +#include + +constexpr std::initializer_list test{2, 1}; +constexpr auto x = std::minmax_element(test.begin(), test.end()); +constexpr auto y = std::minmax_element(test.begin(), test.end(), + std::greater()); +static_assert(x.first == test.begin()+1, ""); +static_assert(x.second == test.begin(), ""); +static_assert(y.first == test.begin(), ""); +static_assert(y.second == test.begin()+1, ""); + diff --git a/libstdc++-v3/testsuite/ext/profile/mutex_extensions_neg.cc b/libstdc++-v3/testsuite/ext/profile/mutex_extensions_neg.cc index 292bee817ad..f89a1063f55 100644 --- a/libstdc++-v3/testsuite/ext/profile/mutex_extensions_neg.cc +++ b/libstdc++-v3/testsuite/ext/profile/mutex_extensions_neg.cc @@ -25,4 +25,4 @@ #include -// { dg-error "multiple inlined namespaces" "" { target *-*-* } 310 } +// { dg-error "multiple inlined namespaces" "" { target *-*-* } 318 }