]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Implement the <array> part of C++20 p1032 Misc constexpr bits.
authorEdward Smith-Rowland <3dw4rd@verizon.net>
Fri, 15 Nov 2019 00:09:49 +0000 (00:09 +0000)
committerEdward Smith-Rowland <emsr@gcc.gnu.org>
Fri, 15 Nov 2019 00:09:49 +0000 (00:09 +0000)
2019-11-14  Edward Smith-Rowland  <3dw4rd@verizon.net>

Implement the <array> part of C++20 p1032 Misc constexpr bits.
* include/std/array (fill, swap): Make constexpr.
* testsuite/23_containers/array/requirements/constexpr_fill.cc: New.
* testsuite/23_containers/array/requirements/constexpr_swap.cc: New.

From-SVN: r278269

libstdc++-v3/ChangeLog
libstdc++-v3/include/std/array
libstdc++-v3/testsuite/23_containers/array/requirements/constexpr_fill.cc [new file with mode: 0644]
libstdc++-v3/testsuite/23_containers/array/requirements/constexpr_swap.cc [new file with mode: 0644]

index 3714e74bb2323f1a5a94a65b76ba5bf3018f68b3..13cca24e368fa631dbdc27d149ed832e32609d8b 100644 (file)
@@ -1,3 +1,10 @@
+2019-11-14  Edward Smith-Rowland  <3dw4rd@verizon.net>
+
+       Implement the <array> part of C++20 p1032 Misc constexpr bits.
+       * include/std/array (fill, swap): Make constexpr.
+       * testsuite/23_containers/array/requirements/constexpr_fill.cc: New.
+       * testsuite/23_containers/array/requirements/constexpr_swap.cc: New.
+
 2019-11-14  Jonathan Wakely  <jwakely@redhat.com>
 
        * include/bits/iterator_concepts.h (__iter_concept_impl): Add
index b1dc888778728549337dcfb33315984f1d9c3528..9ad1e652b6c281e7865938d7b3cba7b1c5cac1ce 100644 (file)
@@ -112,11 +112,11 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
       // No explicit construct/copy/destroy for aggregate type.
 
       // DR 776.
-      void
+      _GLIBCXX20_CONSTEXPR void
       fill(const value_type& __u)
       { std::fill_n(begin(), size(), __u); }
 
-      void
+      _GLIBCXX20_CONSTEXPR void
       swap(array& __other)
       noexcept(_AT_Type::_Is_nothrow_swappable::value)
       { std::swap_ranges(begin(), end(), __other.begin()); }
@@ -288,6 +288,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
 
   // Specialized algorithms.
   template<typename _Tp, std::size_t _Nm>
+    _GLIBCXX20_CONSTEXPR
     inline
 #if __cplusplus > 201402L || !defined(__STRICT_ANSI__) // c++1z or gnu++11
     // Constrained free swap overload, see p0185r1
@@ -295,7 +296,6 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
       _GLIBCXX_STD_C::__array_traits<_Tp, _Nm>::_Is_swappable::value
     >::type
 #else
-    _GLIBCXX20_CONSTEXPR
     void
 #endif
     swap(array<_Tp, _Nm>& __one, array<_Tp, _Nm>& __two)
diff --git a/libstdc++-v3/testsuite/23_containers/array/requirements/constexpr_fill.cc b/libstdc++-v3/testsuite/23_containers/array/requirements/constexpr_fill.cc
new file mode 100644 (file)
index 0000000..30a1555
--- /dev/null
@@ -0,0 +1,36 @@
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+//
+// Copyright (C) 2019 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 <array>
+
+constexpr bool
+test_array()
+{
+  auto ok = true;
+
+  std::array<float,3> fa{};
+  fa.fill(3.333f);
+
+  ok = ok && (fa[0] == fa[2]);
+
+  return ok;
+}
+
+static_assert(test_array());
diff --git a/libstdc++-v3/testsuite/23_containers/array/requirements/constexpr_swap.cc b/libstdc++-v3/testsuite/23_containers/array/requirements/constexpr_swap.cc
new file mode 100644 (file)
index 0000000..3d5d81d
--- /dev/null
@@ -0,0 +1,43 @@
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+//
+// Copyright (C) 2019 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 <array>
+
+constexpr bool
+test_array()
+{
+  auto ok = true;
+
+  std::array<float,3> fa{{1.1f, 2.2f, 3.3f}};
+
+  std::array<float,3> fb{{4.4f, 5.5f, 6.6f}};
+
+  fb.swap(fa);
+
+  ok = ok && (fa[0] == 4.4f);
+
+  std::swap(fa, fb);
+
+  ok = ok && (fa[0] == 1.1f);
+
+  return ok;
+}
+
+static_assert(test_array());