From: Benjamin Kosnik Date: Sat, 23 Jul 2011 03:17:11 +0000 (+0000) Subject: move.h (move, forward): Mark constexpr. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=9b9e81a0a9cef8e9053339f92f9f1be3a13890ea;p=gcc.git move.h (move, forward): Mark constexpr. 2011-07-22 Benjamin Kosnik Daniel Krugler * 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 From-SVN: r176672 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 276f0bfe89e..d76a2daecaf 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,11 @@ +2011-07-22 Benjamin Kosnik + Daniel Krugler + + * 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 * fragment.am (CONFIG_CXXFLAGS): Add -frandom-seed. diff --git a/libstdc++-v3/include/bits/move.h b/libstdc++-v3/include/bits/move.h index e82e36d892e..28d2ae1b3ae 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 - inline _Tp&& + inline constexpr _Tp&& forward(typename std::remove_reference<_Tp>::type& __t) noexcept { return static_cast<_Tp&&>(__t); } template - 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 - inline typename std::remove_reference<_Tp>::type&& + inline constexpr typename std::remove_reference<_Tp>::type&& move(_Tp&& __t) noexcept { return static_cast::type&&>(__t); } diff --git a/libstdc++-v3/include/bits/stl_pair.h b/libstdc++-v3/include/bits/stl_pair.h index 61ebc719040..abd8bd81587 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::value>::type> - pair(_U1&& __x, const _T2& __y) + constexpr pair(_U1&& __x, const _T2& __y) : first(std::forward<_U1>(__x)), second(__y) { } template::value>::type> - pair(const _T1& __x, _U2&& __y) + constexpr pair(const _T1& __x, _U2&& __y) : first(__x), second(std::forward<_U2>(__y)) { } template, 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, 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 - inline pair::__type, - typename __decay_and_strip<_T2>::__type> + inline constexpr pair::__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 1c854627ed4..9b812390d99 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 pair_type; + __gnu_test::constexpr_default_constructible test1; - test1.operator()>(); + test1.operator()(); __gnu_test::constexpr_single_value_constructible test2; - test2.operator(), std::pair>(); - test2.operator(), std::pair>(); + test2.operator()(); + test2.operator()>(); // test 3 const int i1(129); const int i2(6); - constexpr std::pair 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 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 00000000000..4d26f50cb01 --- /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 +// . + + +// 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 +#include + +void +test1() +{ + bool test __attribute__((unused)) = true; + typedef std::pair pair_type; + constexpr pair_type p1 = std::make_pair(22, 22.222); +} + +int +main() +{ + test1(); + return 0; +}