Commit a7d0c94e by Benjamin Kosnik Committed by Benjamin Kosnik

tuple (_Tuple_impl::_M_head, _M_tail): Mark constexpr.

2011-09-06  Benjamin Kosnik  <bkoz@redhat.com>

	* include/std/tuple (_Tuple_impl::_M_head, _M_tail): Mark constexpr.
	(tuple(tuple&&)): Same.
	(tuple(const tuple<_UElements...>& __in)): Same.
	(tuple(tuple<_UElements...>&& __in)): Same.
	(tuple_cat(const tuple<_TElements...>&, const tuple<_UElements...>&)):
	Same.
	(get): Same.
	* include/std/array: Consolidate array::data usage.
	* testsuite/23_containers/array/requirements/constexpr_functions.cc:
	Remove extra include.
	* testsuite/20_util/tuple/creation_functions/constexpr.cc: New.
	* testsuite/20_util/tuple/cons/constexpr-2.cc: Add tests.
	* testsuite/20_util/tuple/cons/constexpr-3.cc: Same.
	* testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Adjust line numbers.

From-SVN: r178620
parent 7b50d234
2011-09-06 Benjamin Kosnik <bkoz@redhat.com>
* include/std/tuple (_Tuple_impl::_M_head, _M_tail): Mark constexpr.
(tuple(tuple&&)): Same.
(tuple(const tuple<_UElements...>& __in)): Same.
(tuple(tuple<_UElements...>&& __in)): Same.
(tuple_cat(const tuple<_TElements...>&, const tuple<_UElements...>&)):
Same.
(get): Same.
* include/std/array: Consolidate array::data usage.
* testsuite/23_containers/array/requirements/constexpr_functions.cc:
Remove extra include.
* testsuite/20_util/tuple/creation_functions/constexpr.cc: New.
* testsuite/20_util/tuple/cons/constexpr-2.cc: Add tests.
* testsuite/20_util/tuple/cons/constexpr-3.cc: Same.
* testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Adjust line numbers.
2011-09-06 François Dumont <fdumont@gcc.gnu.org> 2011-09-06 François Dumont <fdumont@gcc.gnu.org>
Paolo Carlini <paolo.carlini@oracle.com> Paolo Carlini <paolo.carlini@oracle.com>
......
...@@ -61,8 +61,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -61,8 +61,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
struct array struct array
{ {
typedef _Tp value_type; typedef _Tp value_type;
typedef _Tp* pointer; typedef value_type* pointer;
typedef const _Tp* const_pointer; typedef const value_type* const_pointer;
typedef value_type& reference; typedef value_type& reference;
typedef const value_type& const_reference; typedef const value_type& const_reference;
typedef value_type* iterator; typedef value_type* iterator;
...@@ -90,19 +90,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -90,19 +90,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// Iterators. // Iterators.
iterator iterator
begin() noexcept begin() noexcept
{ return iterator(std::__addressof(_M_instance[0])); } { return iterator(data()); }
const_iterator const_iterator
begin() const noexcept begin() const noexcept
{ return const_iterator(std::__addressof(_M_instance[0])); } { return const_iterator(data()); }
iterator iterator
end() noexcept end() noexcept
{ return iterator(std::__addressof(_M_instance[_Nm])); } { return iterator(data() + _Nm); }
const_iterator const_iterator
end() const noexcept end() const noexcept
{ return const_iterator(std::__addressof(_M_instance[_Nm])); } { return const_iterator(data() + _Nm); }
reverse_iterator reverse_iterator
rbegin() noexcept rbegin() noexcept
...@@ -195,11 +195,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -195,11 +195,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
back() const back() const
{ return _Nm ? *(end() - 1) : *end(); } { return _Nm ? *(end() - 1) : *end(); }
_Tp* pointer
data() noexcept data() noexcept
{ return std::__addressof(_M_instance[0]); } { return std::__addressof(_M_instance[0]); }
const _Tp* const_pointer
data() const noexcept data() const noexcept
{ return std::__addressof(_M_instance[0]); } { return std::__addressof(_M_instance[0]); }
}; };
......
...@@ -143,7 +143,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -143,7 +143,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_Head& _Head&
_M_head() noexcept { return *this; } _M_head() noexcept { return *this; }
const _Head& constexpr const _Head&
_M_head() const noexcept { return *this; } _M_head() const noexcept { return *this; }
}; };
...@@ -189,7 +189,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -189,7 +189,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_Head& _Head&
_M_head() noexcept { return _M_head_impl; } _M_head() noexcept { return _M_head_impl; }
const _Head& constexpr const _Head&
_M_head() const noexcept { return _M_head_impl; } _M_head() const noexcept { return _M_head_impl; }
_Head _M_head_impl; _Head _M_head_impl;
...@@ -248,13 +248,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -248,13 +248,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_Head& _Head&
_M_head() noexcept { return _Base::_M_head(); } _M_head() noexcept { return _Base::_M_head(); }
const _Head& constexpr const _Head&
_M_head() const noexcept { return _Base::_M_head(); } _M_head() const noexcept { return _Base::_M_head(); }
_Inherited& _Inherited&
_M_tail() noexcept { return *this; } _M_tail() noexcept { return *this; }
const _Inherited& constexpr const _Inherited&
_M_tail() const noexcept { return *this; } _M_tail() const noexcept { return *this; }
constexpr _Tuple_impl() constexpr _Tuple_impl()
...@@ -280,7 +280,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -280,7 +280,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_Base(std::forward<_Head>(__in._M_head())) { } _Base(std::forward<_Head>(__in._M_head())) { }
template<typename... _UElements> template<typename... _UElements>
_Tuple_impl(const _Tuple_impl<_Idx, _UElements...>& __in) constexpr _Tuple_impl(const _Tuple_impl<_Idx, _UElements...>& __in)
: _Inherited(__in._M_tail()), _Base(__in._M_head()) { } : _Inherited(__in._M_tail()), _Base(__in._M_head()) { }
template<typename _UHead, typename... _UTails> template<typename _UHead, typename... _UTails>
...@@ -409,7 +409,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -409,7 +409,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
constexpr tuple(const tuple&) = default; constexpr tuple(const tuple&) = default;
tuple(tuple&&) = default; constexpr tuple(tuple&&) = default;
template<typename... _UElements, typename = typename template<typename... _UElements, typename = typename
enable_if<__and_<integral_constant<bool, sizeof...(_UElements) enable_if<__and_<integral_constant<bool, sizeof...(_UElements)
...@@ -417,7 +417,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -417,7 +417,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
__all_convertible<__conv_types<const _UElements&...>, __all_convertible<__conv_types<const _UElements&...>,
__conv_types<_Elements...>> __conv_types<_Elements...>>
>::value>::type> >::value>::type>
tuple(const tuple<_UElements...>& __in) constexpr tuple(const tuple<_UElements...>& __in)
: _Inherited(static_cast<const _Tuple_impl<0, _UElements...>&>(__in)) : _Inherited(static_cast<const _Tuple_impl<0, _UElements...>&>(__in))
{ } { }
...@@ -427,7 +427,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -427,7 +427,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
__all_convertible<__conv_types<_UElements...>, __all_convertible<__conv_types<_UElements...>,
__conv_types<_Elements...>> __conv_types<_Elements...>>
>::value>::type> >::value>::type>
tuple(tuple<_UElements...>&& __in) constexpr tuple(tuple<_UElements...>&& __in)
: _Inherited(static_cast<_Tuple_impl<0, _UElements...>&&>(__in)) { } : _Inherited(static_cast<_Tuple_impl<0, _UElements...>&&>(__in)) { }
// Allocator-extended constructors. // Allocator-extended constructors.
...@@ -548,18 +548,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -548,18 +548,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
constexpr tuple(const tuple&) = default; constexpr tuple(const tuple&) = default;
tuple(tuple&&) = default; constexpr tuple(tuple&&) = default;
template<typename _U1, typename _U2, typename = typename template<typename _U1, typename _U2, typename = typename
enable_if<__and_<is_convertible<const _U1&, _T1>, enable_if<__and_<is_convertible<const _U1&, _T1>,
is_convertible<const _U2&, _T2>>::value>::type> is_convertible<const _U2&, _T2>>::value>::type>
tuple(const tuple<_U1, _U2>& __in) constexpr tuple(const tuple<_U1, _U2>& __in)
: _Inherited(static_cast<const _Tuple_impl<0, _U1, _U2>&>(__in)) { } : _Inherited(static_cast<const _Tuple_impl<0, _U1, _U2>&>(__in)) { }
template<typename _U1, typename _U2, typename = typename template<typename _U1, typename _U2, typename = typename
enable_if<__and_<is_convertible<_U1, _T1>, enable_if<__and_<is_convertible<_U1, _T1>,
is_convertible<_U2, _T2>>::value>::type> is_convertible<_U2, _T2>>::value>::type>
tuple(tuple<_U1, _U2>&& __in) constexpr tuple(tuple<_U1, _U2>&& __in)
: _Inherited(static_cast<_Tuple_impl<0, _U1, _U2>&&>(__in)) { } : _Inherited(static_cast<_Tuple_impl<0, _U1, _U2>&&>(__in)) { }
template<typename _U1, typename _U2, typename = typename template<typename _U1, typename _U2, typename = typename
...@@ -571,7 +571,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -571,7 +571,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _U1, typename _U2, typename = typename template<typename _U1, typename _U2, typename = typename
enable_if<__and_<is_convertible<_U1, _T1>, enable_if<__and_<is_convertible<_U1, _T1>,
is_convertible<_U2, _T2>>::value>::type> is_convertible<_U2, _T2>>::value>::type>
tuple(pair<_U1, _U2>&& __in) constexpr tuple(pair<_U1, _U2>&& __in)
: _Inherited(std::forward<_U1>(__in.first), : _Inherited(std::forward<_U1>(__in.first),
std::forward<_U2>(__in.second)) { } std::forward<_U2>(__in.second)) { }
...@@ -752,7 +752,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -752,7 +752,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ return __t._M_head(); } { return __t._M_head(); }
template<std::size_t __i, typename _Head, typename... _Tail> template<std::size_t __i, typename _Head, typename... _Tail>
inline typename __add_c_ref<_Head>::type inline constexpr typename __add_c_ref<_Head>::type
__get_helper(const _Tuple_impl<__i, _Head, _Tail...>& __t) noexcept __get_helper(const _Tuple_impl<__i, _Head, _Tail...>& __t) noexcept
{ return __t._M_head(); } { return __t._M_head(); }
...@@ -767,7 +767,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -767,7 +767,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ return __get_helper<__i>(__t); } { return __get_helper<__i>(__t); }
template<std::size_t __i, typename... _Elements> template<std::size_t __i, typename... _Elements>
inline typename __add_c_ref< inline constexpr typename __add_c_ref<
typename tuple_element<__i, tuple<_Elements...>>::type typename tuple_element<__i, tuple<_Elements...>>::type
>::type >::type
get(const tuple<_Elements...>& __t) noexcept get(const tuple<_Elements...>& __t) noexcept
...@@ -789,13 +789,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -789,13 +789,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<std::size_t __i, std::size_t __j, typename _Tp, typename _Up> template<std::size_t __i, std::size_t __j, typename _Tp, typename _Up>
struct __tuple_compare<0, __i, __j, _Tp, _Up> struct __tuple_compare<0, __i, __j, _Tp, _Up>
{ {
static bool __eq(const _Tp& __t, const _Up& __u) static bool
__eq(const _Tp& __t, const _Up& __u)
{ {
return (get<__i>(__t) == get<__i>(__u) && return (get<__i>(__t) == get<__i>(__u) &&
__tuple_compare<0, __i + 1, __j, _Tp, _Up>::__eq(__t, __u)); __tuple_compare<0, __i + 1, __j, _Tp, _Up>::__eq(__t, __u));
} }
static bool __less(const _Tp& __t, const _Up& __u) static bool
__less(const _Tp& __t, const _Up& __u)
{ {
return ((get<__i>(__t) < get<__i>(__u)) return ((get<__i>(__t) < get<__i>(__u))
|| !(get<__i>(__u) < get<__i>(__t)) && || !(get<__i>(__u) < get<__i>(__t)) &&
...@@ -806,11 +808,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -806,11 +808,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<std::size_t __i, typename _Tp, typename _Up> template<std::size_t __i, typename _Tp, typename _Up>
struct __tuple_compare<0, __i, __i, _Tp, _Up> struct __tuple_compare<0, __i, __i, _Tp, _Up>
{ {
static bool __eq(const _Tp&, const _Up&) static bool
{ return true; } __eq(const _Tp&, const _Up&) { return true; }
static bool __less(const _Tp&, const _Up&) static bool
{ return false; } __less(const _Tp&, const _Up&) { return false; }
}; };
template<typename... _TElements, typename... _UElements> template<typename... _TElements, typename... _UElements>
...@@ -899,7 +901,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -899,7 +901,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename... _TElements, std::size_t... _TIdx, template<typename... _TElements, std::size_t... _TIdx,
typename... _UElements, std::size_t... _UIdx> typename... _UElements, std::size_t... _UIdx>
inline tuple<_TElements..., _UElements...> inline constexpr tuple<_TElements..., _UElements...>
__tuple_cat_helper(const tuple<_TElements...>& __t, __tuple_cat_helper(const tuple<_TElements...>& __t,
const __index_holder<_TIdx...>&, const __index_holder<_TIdx...>&,
const tuple<_UElements...>& __u, const tuple<_UElements...>& __u,
...@@ -939,7 +941,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -939,7 +941,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
std::forward<_UElements>(get<_UIdx>(__u))...); } std::forward<_UElements>(get<_UIdx>(__u))...); }
template<typename... _TElements, typename... _UElements> template<typename... _TElements, typename... _UElements>
inline tuple<_TElements..., _UElements...> inline constexpr tuple<_TElements..., _UElements...>
tuple_cat(const tuple<_TElements...>& __t, const tuple<_UElements...>& __u) tuple_cat(const tuple<_TElements...>& __t, const tuple<_UElements...>& __u)
{ {
return __tuple_cat_helper(__t, typename return __tuple_cat_helper(__t, typename
...@@ -1032,8 +1034,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -1032,8 +1034,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<class _T1, class _T2> template<class _T1, class _T2>
template<typename _Tp, typename... _Args> template<typename _Tp, typename... _Args>
inline _Tp inline _Tp
pair<_T1, _T2>:: pair<_T1, _T2>::__cons(tuple<_Args...>&& __tuple)
__cons(tuple<_Args...>&& __tuple)
{ {
typedef typename _Build_index_tuple<sizeof...(_Args)>::__type typedef typename _Build_index_tuple<sizeof...(_Args)>::__type
_Indexes; _Indexes;
...@@ -1043,8 +1044,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -1043,8 +1044,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<class _T1, class _T2> template<class _T1, class _T2>
template<typename _Tp, typename... _Args, int... _Indexes> template<typename _Tp, typename... _Args, int... _Indexes>
inline _Tp inline _Tp
pair<_T1, _T2>:: pair<_T1, _T2>::__do_cons(tuple<_Args...>&& __tuple,
__do_cons(tuple<_Args...>&& __tuple,
const _Index_tuple<_Indexes...>&) const _Index_tuple<_Indexes...>&)
{ return _Tp(std::forward<_Args>(get<_Indexes>(__tuple))...); } { return _Tp(std::forward<_Args>(get<_Indexes>(__tuple))...); }
......
...@@ -56,8 +56,8 @@ int main() ...@@ -56,8 +56,8 @@ int main()
test2.operator()<tuple_type, std::pair<short, short>>(); test2.operator()<tuple_type, std::pair<short, short>>();
// 07: different-tuple-type conversion constructor // 07: different-tuple-type conversion constructor
// test2.operator()<tuple_type, std::tuple<short, short>>(); test2.operator()<tuple_type, std::tuple<short, short>>();
// test2.operator()<std::tuple<short, short>, tuple_type>(); test2.operator()<std::tuple<short, short>, tuple_type>();
return 0; return 0;
} }
...@@ -53,8 +53,8 @@ int main() ...@@ -53,8 +53,8 @@ int main()
constexpr tuple_type t8(i5, i6, i7); constexpr tuple_type t8(i5, i6, i7);
// 06: different-tuple-type conversion constructor // 06: different-tuple-type conversion constructor
// test2.operator()<tuple_type, std::tuple<short, short, short>>(); test2.operator()<tuple_type, std::tuple<short, short, short>>();
// test2.operator()<std::tuple<short, short, short>, tuple_type>(); test2.operator()<std::tuple<short, short, short>, tuple_type>();
return 0; return 0;
} }
// { 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 <tuple>
bool test __attribute__((unused)) = true;
// make_tuple
#if 0
void
test_make_tuple()
{
{
typedef std::tuple<int, float> tuple_type;
constexpr tuple_type p1 = std::make_tuple(22, 22.222);
}
{
typedef std::tuple<int, float, int> tuple_type;
constexpr tuple_type p1 = std::make_tuple(22, 22.222, 77799);
}
}
#endif
// get
void
test_get()
{
{
typedef std::tuple<int, float> tuple_type;
constexpr tuple_type t1 { 55, 77.77 };
constexpr auto var = std::get<1>(t1);
}
{
typedef std::tuple<int, float, int> tuple_type;
constexpr tuple_type t1 { 55, 77.77, 99 };
constexpr auto var = std::get<2>(t1);
}
}
// tuple_cat
void
test_tuple_cat()
{
typedef std::tuple<int, float> tuple_type1;
typedef std::tuple<int, int, float> tuple_type2;
constexpr tuple_type1 t1 { 55, 77.77 };
constexpr tuple_type2 t2 { 55, 99, 77.77 };
constexpr auto cat1 = std::tuple_cat(t1, t2);
}
int
main()
{
#if 0
test_make_tuple();
#endif
test_get();
test_tuple_cat();
return 0;
}
...@@ -51,7 +51,7 @@ main() ...@@ -51,7 +51,7 @@ main()
// { dg-warning "note" "" { target *-*-* } 485 } // { dg-warning "note" "" { target *-*-* } 485 }
// { dg-warning "note" "" { target *-*-* } 479 } // { dg-warning "note" "" { target *-*-* } 479 }
// { dg-warning "note" "" { target *-*-* } 468 } // { dg-warning "note" "" { target *-*-* } 468 }
// { dg-warning "note" "" { target *-*-* } 829 } // { dg-warning "note" "" { target *-*-* } 831 }
// { dg-warning "note" "" { target *-*-* } 1056 } // { dg-warning "note" "" { target *-*-* } 1056 }
// { dg-warning "note" "" { target *-*-* } 1050 } // { dg-warning "note" "" { target *-*-* } 1050 }
// { dg-warning "note" "" { target *-*-* } 342 } // { dg-warning "note" "" { target *-*-* } 342 }
......
// { dg-do compile } // { dg-do compile }
// { dg-options "-std=gnu++0x" } // { 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 // 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 // software; you can redistribute it and/or modify it under the
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
// <http://www.gnu.org/licenses/>. // <http://www.gnu.org/licenses/>.
#include <array> #include <array>
#include <testsuite_common_types.h>
namespace __gnu_test namespace __gnu_test
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment