move.h (move_if_noexcept): Mark constexpr.
authorBenjamin Kosnik <bkoz@redhat.com>
Thu, 18 Oct 2012 08:36:06 +0000 (08:36 +0000)
committerBenjamin Kosnik <bkoz@gcc.gnu.org>
Thu, 18 Oct 2012 08:36:06 +0000 (08:36 +0000)
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

14 files changed:
libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/move.h
libstdc++-v3/include/std/array
libstdc++-v3/include/std/chrono
libstdc++-v3/include/std/tuple
libstdc++-v3/testsuite/20_util/forward/c_neg.cc
libstdc++-v3/testsuite/20_util/forward/f_neg.cc
libstdc++-v3/testsuite/20_util/move_if_noexcept/constexpr.cc [new file with mode: 0644]
libstdc++-v3/testsuite/20_util/tuple/comparison_operators/35480_neg.cc
libstdc++-v3/testsuite/20_util/tuple/comparison_operators/constexpr.cc [new file with mode: 0644]
libstdc++-v3/testsuite/20_util/tuple/creation_functions/constexpr.cc
libstdc++-v3/testsuite/23_containers/array/element_access/constexpr_element_access.cc
libstdc++-v3/testsuite/23_containers/array/tuple_interface/get_neg.cc
libstdc++-v3/testsuite/23_containers/array/tuple_interface/tuple_element_neg.cc

index 3527fbccc9d060bd529068c29ca4fa3fdfbb3f3f..709f47986c02c683ab0143e774e2f914a4170dd6 100644 (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
index 353c466d8fce366ef75ed33cb35c6ce2b7e8cce9..236f0de300ab2d6053e144987a414505319ad6f5 100644 (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); }
index c7c0a5ae82457c96ed3321f57026160214541132..15dd6c13222ea430f0026e081576515877ea683f 100644 (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
index 209f395ed3d97837811fc5f3a03918c853f8bacc..d920a7dd379898a7add1c3bdde907bfbbf4d023b 100644 (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
index fb9e09fffe890ff62f5ac265f2e1606336d8b58e..b4985d280d88229b24eef7bbe68e33022c7e5081 100644 (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)...); }
 
index 01128245d7e7c9fbccaa96039c9d6eae699d85f4..1e573ec2757d25c05af52ffb2cfa3f96685b2817 100644 (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>
 
index 9e5b78a04db3e8dcd41c7ba6222e9a316ed6f451..d4a9c7a2af63d53afca6200a134560657f51cc4a 100644 (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>
 
diff --git a/libstdc++-v3/testsuite/20_util/move_if_noexcept/constexpr.cc b/libstdc++-v3/testsuite/20_util/move_if_noexcept/constexpr.cc
new file mode 100644 (file)
index 0000000..4811b17
--- /dev/null
@@ -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;
+}
index eb22938261a8a85e8f71dfbb2715f6d00350b0ef..eb4c213eddb9141df66109c1360b9a68ca0ed9ba 100644 (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" }
diff --git a/libstdc++-v3/testsuite/20_util/tuple/comparison_operators/constexpr.cc b/libstdc++-v3/testsuite/20_util/tuple/comparison_operators/constexpr.cc
new file mode 100644 (file)
index 0000000..0efb4c3
--- /dev/null
@@ -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;
+}
index bf2a8573abfd9fa0b664fbf1d6c21d2f5c5e18a5..6c260605c05e6b1162ad682dd046bdec5e7edfaa 100644 (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()
index c2f301adcd4b7cb27867a425672b83cb15795a99..ec46ac0d38899ea8a8cbb3b5876b7f88104ed3ee 100644 (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;
 }
index e74af1b4f43adac5d06d7fb88f4c496258db7469..7c7a365cb4e425aca4102f4952e276160822ddfc 100644 (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 }
index b9ce910f61a4073dd7a7b0845232e0e9099b2620..3c642c800b057b2c91379ad286f7b2a1d3306b89 100644 (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 }