diff options
author | Benjamin Kosnik <bkoz@redhat.com> | 2011-07-23 03:17:11 +0000 |
---|---|---|
committer | Benjamin Kosnik <bkoz@gcc.gnu.org> | 2011-07-23 03:17:11 +0000 |
commit | 9b9e81a0a9cef8e9053339f92f9f1be3a13890ea (patch) | |
tree | 91438aa522099078f99fff44746880494507cf5a | |
parent | 15c2ccbac51d3e17c4524946bbf1ee44c6e7f811 (diff) | |
download | gcc-9b9e81a0a9cef8e9053339f92f9f1be3a13890ea.zip gcc-9b9e81a0a9cef8e9053339f92f9f1be3a13890ea.tar.gz gcc-9b9e81a0a9cef8e9053339f92f9f1be3a13890ea.tar.bz2 |
move.h (move, forward): Mark constexpr.
2011-07-22 Benjamin Kosnik <bkoz@redhat.com>
Daniel Krugler <daniel.kruegler@googlemail.com>
* include/bits/move.h (move, forward): Mark constexpr.
* include/bits/stl_pair.h (pair): Mark move ctors constexpr.
* testsuite/20_util/pair/make_pair/constexpr.cc: New.
* testsuite/20_util/pair/cons/constexpr.cc: Add tests.
Co-Authored-By: Daniel Krugler <daniel.kruegler@googlemail.com>
From-SVN: r176672
-rw-r--r-- | libstdc++-v3/ChangeLog | 8 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/move.h | 6 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/stl_pair.h | 12 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/20_util/pair/cons/constexpr.cc | 26 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/20_util/pair/make_pair/constexpr.cc | 42 |
5 files changed, 80 insertions, 14 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 276f0bf..d76a2da 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,11 @@ +2011-07-22 Benjamin Kosnik <bkoz@redhat.com> + Daniel Krugler <daniel.kruegler@googlemail.com> + + * include/bits/move.h (move, forward): Mark constexpr. + * include/bits/stl_pair.h (pair): Mark move ctors constexpr. + * testsuite/20_util/pair/make_pair/constexpr.cc: New. + * testsuite/20_util/pair/cons/constexpr.cc: Add tests. + 2011-07-22 Ian Lance Taylor <iant@google.com> * fragment.am (CONFIG_CXXFLAGS): Add -frandom-seed. diff --git a/libstdc++-v3/include/bits/move.h b/libstdc++-v3/include/bits/move.h index e82e36d..28d2ae1 100644 --- a/libstdc++-v3/include/bits/move.h +++ b/libstdc++-v3/include/bits/move.h @@ -58,12 +58,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// forward (as per N3143) template<typename _Tp> - inline _Tp&& + inline constexpr _Tp&& forward(typename std::remove_reference<_Tp>::type& __t) noexcept { return static_cast<_Tp&&>(__t); } template<typename _Tp> - inline _Tp&& + inline constexpr _Tp&& forward(typename std::remove_reference<_Tp>::type&& __t) noexcept { static_assert(!std::is_lvalue_reference<_Tp>::value, "template argument" @@ -78,7 +78,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @return Same, moved. */ template<typename _Tp> - inline typename std::remove_reference<_Tp>::type&& + inline constexpr typename std::remove_reference<_Tp>::type&& move(_Tp&& __t) noexcept { return static_cast<typename std::remove_reference<_Tp>::type&&>(__t); } diff --git a/libstdc++-v3/include/bits/stl_pair.h b/libstdc++-v3/include/bits/stl_pair.h index 61ebc71..abd8bd8 100644 --- a/libstdc++-v3/include/bits/stl_pair.h +++ b/libstdc++-v3/include/bits/stl_pair.h @@ -128,24 +128,24 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // DR 811. template<class _U1, class = typename enable_if<is_convertible<_U1, _T1>::value>::type> - pair(_U1&& __x, const _T2& __y) + constexpr pair(_U1&& __x, const _T2& __y) : first(std::forward<_U1>(__x)), second(__y) { } template<class _U2, class = typename enable_if<is_convertible<_U2, _T2>::value>::type> - pair(const _T1& __x, _U2&& __y) + constexpr pair(const _T1& __x, _U2&& __y) : first(__x), second(std::forward<_U2>(__y)) { } template<class _U1, class _U2, class = typename enable_if<__and_<is_convertible<_U1, _T1>, is_convertible<_U2, _T2>>::value>::type> - pair(_U1&& __x, _U2&& __y) + constexpr pair(_U1&& __x, _U2&& __y) : first(std::forward<_U1>(__x)), second(std::forward<_U2>(__y)) { } template<class _U1, class _U2, class = typename enable_if<__and_<is_convertible<_U1, _T1>, is_convertible<_U2, _T2>>::value>::type> - pair(pair<_U1, _U2>&& __p) + constexpr pair(pair<_U1, _U2>&& __p) : first(std::forward<_U1>(__p.first)), second(std::forward<_U2>(__p.second)) { } @@ -275,8 +275,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #ifdef __GXX_EXPERIMENTAL_CXX0X__ // NB: DR 706. template<class _T1, class _T2> - inline pair<typename __decay_and_strip<_T1>::__type, - typename __decay_and_strip<_T2>::__type> + inline constexpr pair<typename __decay_and_strip<_T1>::__type, + typename __decay_and_strip<_T2>::__type> make_pair(_T1&& __x, _T2&& __y) { typedef typename __decay_and_strip<_T1>::__type __ds_type1; diff --git a/libstdc++-v3/testsuite/20_util/pair/cons/constexpr.cc b/libstdc++-v3/testsuite/20_util/pair/cons/constexpr.cc index 1c85462..9b81239 100644 --- a/libstdc++-v3/testsuite/20_util/pair/cons/constexpr.cc +++ b/libstdc++-v3/testsuite/20_util/pair/cons/constexpr.cc @@ -1,7 +1,7 @@ // { dg-do compile } // { dg-options "-std=gnu++0x" } -// Copyright (C) 2010 Free Software Foundation, Inc. +// Copyright (C) 2010, 2011 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 @@ -23,17 +23,33 @@ int main() { + typedef std::pair<int, int> pair_type; + __gnu_test::constexpr_default_constructible test1; - test1.operator()<std::pair<int, int>>(); + test1.operator()<pair_type>(); __gnu_test::constexpr_single_value_constructible test2; - test2.operator()<std::pair<int, int>, std::pair<int, int>>(); - test2.operator()<std::pair<int, int>, std::pair<short, short>>(); + test2.operator()<pair_type, pair_type>(); + test2.operator()<pair_type, std::pair<short, short>>(); // test 3 const int i1(129); const int i2(6); - constexpr std::pair<int, int> p3(i1, i2); + constexpr pair_type p0(i1, i2); + + // test 4 + constexpr int i(999); + constexpr pair_type p1 { 44, 90 }; + constexpr pair_type p2 { std::move(p1.first), i }; + constexpr pair_type p3 { i, std::move(p1.second) }; + + constexpr pair_type p5 { 444, 904 }; + constexpr pair_type p6 { std::move(p5.first), std::move(p5.second) }; + + constexpr std::pair<char, char> p8 { 'a', 'z' }; + constexpr pair_type p9(std::move(p8)); + + constexpr pair_type p10(std::move(p0)); return 0; } diff --git a/libstdc++-v3/testsuite/20_util/pair/make_pair/constexpr.cc b/libstdc++-v3/testsuite/20_util/pair/make_pair/constexpr.cc new file mode 100644 index 0000000..4d26f50 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/pair/make_pair/constexpr.cc @@ -0,0 +1,42 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2011 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/>. + + +// NOTE: This makes use of the fact that we know how moveable +// is implemented on pair, and also vector. If the implementation +// changes this test may begin to fail. + +#include <memory> +#include <testsuite_hooks.h> + +void +test1() +{ + bool test __attribute__((unused)) = true; + typedef std::pair<int, float> pair_type; + constexpr pair_type p1 = std::make_pair(22, 22.222); +} + +int +main() +{ + test1(); + return 0; +} |