move.h (move_if_noexcept): Mark constexpr.

2012-10-17  Benjamin Kosnik  <bkoz@redhat.com>

	* include/bits/move.h (move_if_noexcept): Mark constexpr.
	* include/std/array (front, back): Same.
	* include/std/chrono: Add comment.
	* include/std/tuple (__tuple_compare): Mark __eq, __less constexpr.
	(operator ==, <, >, !=, <=, >=): Same.
	* testsuite/20_util/forward/c_neg.cc: Adjust line numbers.
	* testsuite/20_util/forward/f_neg.cc: Same.
	* testsuite/20_util/move_if_noexcept/constexpr.cc: New.
	* testsuite/20_util/tuple/comparison_operators/constexpr.cc: New.
	* testsuite/20_util/tuple/creation_functions/constexpr.cc: Add.
	* testsuite/23_containers/array/element_access/
	constexpr_element_access.cc: Same.
	* testsuite/23_containers/array/tuple_interface/get_neg.cc: Adjust
	line numbers.
	* testsuite/23_containers/array/tuple_interface/tuple_element_neg.cc:
	Same.

	* testsuite/20_util/tuple/comparison_operators/35480_neg.cc:
          Temporarily add dg-excess-errors.

From-SVN: r192556
This commit is contained in:
Benjamin Kosnik 2012-10-18 08:36:06 +00:00 committed by Benjamin Kosnik
parent 2167642932
commit a9ba8ba56c
14 changed files with 177 additions and 32 deletions

View File

@ -1,3 +1,25 @@
2012-10-17 Benjamin Kosnik <bkoz@redhat.com>
* include/bits/move.h (move_if_noexcept): Mark constexpr.
* include/std/array (front, back): Same.
* include/std/chrono: Add comment.
* include/std/tuple (__tuple_compare): Mark __eq, __less constexpr.
(operator ==, <, >, !=, <=, >=): Same.
* testsuite/20_util/forward/c_neg.cc: Adjust line numbers.
* testsuite/20_util/forward/f_neg.cc: Same.
* testsuite/20_util/move_if_noexcept/constexpr.cc: New.
* testsuite/20_util/tuple/comparison_operators/constexpr.cc: New.
* testsuite/20_util/tuple/creation_functions/constexpr.cc: Add.
* testsuite/23_containers/array/element_access/
constexpr_element_access.cc: Same.
* testsuite/23_containers/array/tuple_interface/get_neg.cc: Adjust
line numbers.
* testsuite/23_containers/array/tuple_interface/tuple_element_neg.cc:
Same.
* testsuite/20_util/tuple/comparison_operators/35480_neg.cc:
Temporarily add dg-excess-errors.
2012-10-16 François Dumont <fdumont@gcc.gnu.org>
* include/debug/formatter.h (_Debug_msg_id): Add

View File

@ -1,6 +1,6 @@
// Move, forward and identity for C++0x + swap -*- C++ -*-
// Copyright (C) 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
// Copyright (C) 2007-2012 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
@ -65,7 +65,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @{
*/
// forward (as per N3143)
/**
* @brief Forward an lvalue.
* @return The parameter cast to the specified type.
@ -117,7 +116,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* type is copyable, in which case an lvalue-reference is returned instead.
*/
template<typename _Tp>
inline typename
inline constexpr typename
conditional<__move_if_noexcept_cond<_Tp>::value, const _Tp&, _Tp&&>::type
move_if_noexcept(_Tp& __x) noexcept
{ return std::move(__x); }

View File

@ -198,17 +198,20 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
front()
{ return *begin(); }
const_reference
constexpr const_reference
front() const
{ return *begin(); }
{ return _AT_Type::_S_ref(_M_elems, 0); }
reference
back()
{ return _Nm ? *(end() - 1) : *end(); }
const_reference
constexpr const_reference
back() const
{ return _Nm ? *(end() - 1) : *end(); }
{
return _Nm ? _AT_Type::_S_ref(_M_elems, _Nm - 1)
: _AT_Type::_S_ref(_M_elems, _Nm);
}
pointer
data() noexcept

View File

@ -250,7 +250,10 @@ _GLIBCXX_END_NAMESPACE_VERSION
// 20.11.5.1 construction / copy / destroy
constexpr duration() = default;
constexpr duration(const duration&) = default;
// NB: Make constexpr implicit. This cannot be explicitly
// constexpr, as any UDT that is not a literal type with a
// constexpr copy constructor will be ill-formed.
duration(const duration&) = default;
template<typename _Rep2, typename = typename
enable_if<is_convertible<_Rep2, rep>::value

View File

@ -775,14 +775,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<std::size_t __i, std::size_t __j, typename _Tp, typename _Up>
struct __tuple_compare<0, __i, __j, _Tp, _Up>
{
static bool
static constexpr bool
__eq(const _Tp& __t, const _Up& __u)
{
return (get<__i>(__t) == get<__i>(__u) &&
__tuple_compare<0, __i + 1, __j, _Tp, _Up>::__eq(__t, __u));
}
static bool
static constexpr bool
__less(const _Tp& __t, const _Up& __u)
{
return ((get<__i>(__t) < get<__i>(__u))
@ -794,55 +794,55 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<std::size_t __i, typename _Tp, typename _Up>
struct __tuple_compare<0, __i, __i, _Tp, _Up>
{
static bool
static constexpr bool
__eq(const _Tp&, const _Up&) { return true; }
static bool
static constexpr bool
__less(const _Tp&, const _Up&) { return false; }
};
template<typename... _TElements, typename... _UElements>
bool
constexpr bool
operator==(const tuple<_TElements...>& __t,
const tuple<_UElements...>& __u)
{
typedef tuple<_TElements...> _Tp;
typedef tuple<_UElements...> _Up;
return (__tuple_compare<tuple_size<_Tp>::value - tuple_size<_Up>::value,
return bool(__tuple_compare<tuple_size<_Tp>::value - tuple_size<_Up>::value,
0, tuple_size<_Tp>::value, _Tp, _Up>::__eq(__t, __u));
}
template<typename... _TElements, typename... _UElements>
bool
constexpr bool
operator<(const tuple<_TElements...>& __t,
const tuple<_UElements...>& __u)
{
typedef tuple<_TElements...> _Tp;
typedef tuple<_UElements...> _Up;
return (__tuple_compare<tuple_size<_Tp>::value - tuple_size<_Up>::value,
return bool(__tuple_compare<tuple_size<_Tp>::value - tuple_size<_Up>::value,
0, tuple_size<_Tp>::value, _Tp, _Up>::__less(__t, __u));
}
template<typename... _TElements, typename... _UElements>
inline bool
inline constexpr bool
operator!=(const tuple<_TElements...>& __t,
const tuple<_UElements...>& __u)
{ return !(__t == __u); }
template<typename... _TElements, typename... _UElements>
inline bool
inline constexpr bool
operator>(const tuple<_TElements...>& __t,
const tuple<_UElements...>& __u)
{ return __u < __t; }
template<typename... _TElements, typename... _UElements>
inline bool
inline constexpr bool
operator<=(const tuple<_TElements...>& __t,
const tuple<_UElements...>& __u)
{ return !(__u < __t); }
template<typename... _TElements, typename... _UElements>
inline bool
inline constexpr bool
operator>=(const tuple<_TElements...>& __t,
const tuple<_UElements...>& __u)
{ return !(__t < __u); }
@ -858,7 +858,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
template<typename... _Elements>
constexpr tuple<_Elements&&...>
tuple<_Elements&&...>
forward_as_tuple(_Elements&&... __args) noexcept
{ return tuple<_Elements&&...>(std::forward<_Elements>(__args)...); }

View File

@ -1,7 +1,7 @@
// { dg-do compile }
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2010, 2011 Free Software Foundation, Inc.
// Copyright (C) 2010-2012 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
@ -18,7 +18,7 @@
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// { dg-error "static assertion failed" "" { target *-*-* } 90 }
// { dg-error "static assertion failed" "" { target *-*-* } 89 }
#include <list>

View File

@ -1,7 +1,7 @@
// { dg-do compile }
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2010, 2011 Free Software Foundation, Inc.
// Copyright (C) 2010-2012 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
@ -18,7 +18,7 @@
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// { dg-error "static assertion failed" "" { target *-*-* } 90 }
// { dg-error "static assertion failed" "" { target *-*-* } 89 }
#include <utility>

View File

@ -0,0 +1,42 @@
// { dg-do compile }
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2012 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/>.
#include <utility>
#include <testsuite_hooks.h>
struct simple
{
int i;
};
void
test01()
{
bool test __attribute__((unused)) = true;
constexpr simple s { 5 };
constexpr auto s2 __attribute__((unused)) = std::move_if_noexcept(s);
}
int main()
{
test01();
return 0;
}

View File

@ -1,7 +1,7 @@
// { dg-options "-std=gnu++0x" }
// { dg-do compile }
// Copyright (C) 2008, 2009 Free Software Foundation, Inc.
// Copyright (C) 2008, 2009, 2012 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
@ -31,3 +31,4 @@ void test01()
if ( t1 == t2 ) {} // { dg-error "here" }
}
// { dg-prune-output "incomplete type" }
// { dg-excess-errors "body of constexpr function" }

View File

@ -0,0 +1,29 @@
// { dg-do compile }
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2012 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/>.
#include <tuple>
#include <testsuite_common_types.h>
int main()
{
__gnu_test::constexpr_comparison_operators test;
test.operator()<std::tuple<int, int>>();
return 0;
}

View File

@ -1,7 +1,7 @@
// { dg-do compile }
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2011 Free Software Foundation, Inc.
// Copyright (C) 2011, 2012 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
@ -45,6 +45,50 @@ test_make_tuple()
}
}
#if 0
// forward_as_tuple
void
test_forward_as_tuple()
{
{
typedef std::tuple<int, float> tuple_type;
constexpr tuple_type p1 __attribute__((unused))
= std::forward_as_tuple(22, 22.222);
}
{
typedef std::tuple<int, float, int> tuple_type;
constexpr tuple_type p1 __attribute__((unused))
= std::forward_as_tuple(22, 22.222, 77799);
}
}
#endif
#if 0
// tie
void
test_tie()
{
{
int i(22);
float f(22.222);
typedef std::tuple<int, float> tuple_type;
constexpr tuple_type p1 __attribute__((unused))
= std::tie(i, f);
}
{
int i(22);
float f(22.222);
int ii(77799);
typedef std::tuple<int, float, int> tuple_type;
constexpr tuple_type p1 __attribute__((unused))
= std::tie(i, f, ii);
}
}
#endif
// get
void
test_get()

View File

@ -1,7 +1,7 @@
// { dg-do compile }
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2011 Free Software Foundation, Inc.
// Copyright (C) 2011-2012 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
@ -27,5 +27,7 @@ int main()
constexpr array_type a = { { 0, 55, 66, 99, 4115, 2 } };
constexpr auto v1 __attribute__((unused)) = a[1];
constexpr auto v2 __attribute__((unused)) = a.at(2);
constexpr auto v3 __attribute__((unused)) = a.front();
constexpr auto v4 __attribute__((unused)) = a.back();
return 0;
}

View File

@ -27,6 +27,6 @@ int n1 = std::get<1>(a);
int n2 = std::get<1>(std::move(a));
int n3 = std::get<1>(ca);
// { dg-error "static assertion failed" "" { target *-*-* } 288 }
// { dg-error "static assertion failed" "" { target *-*-* } 296 }
// { dg-error "static assertion failed" "" { target *-*-* } 304 }
// { dg-error "static assertion failed" "" { target *-*-* } 291 }
// { dg-error "static assertion failed" "" { target *-*-* } 299 }
// { dg-error "static assertion failed" "" { target *-*-* } 307 }

View File

@ -22,4 +22,4 @@
typedef std::tuple_element<1, std::array<int, 1>>::type type;
// { dg-error "static assertion failed" "" { target *-*-* } 280 }
// { dg-error "static assertion failed" "" { target *-*-* } 283 }