aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2020-12-03 17:08:01 +0000
committerJonathan Wakely <jwakely@redhat.com>2020-12-03 17:08:01 +0000
commit91cfacc4b5d317b12a3bdcd798273a581568f645 (patch)
tree8a0ccc7af231d5bb384b1ae116d356e0afc85024
parenteb8c2b30b947dd8a2012ee658117bea05e46bc85 (diff)
downloadgcc-91cfacc4b5d317b12a3bdcd798273a581568f645.zip
gcc-91cfacc4b5d317b12a3bdcd798273a581568f645.tar.gz
gcc-91cfacc4b5d317b12a3bdcd798273a581568f645.tar.bz2
libstdc++: Disable std::array assertions for C++11 constexpr
The recent changes to add assertions to std::array broke the functions that need to be constexpr in C++11, because of the restrictive rules for constexpr functions in C++11. This simply disables the assertions for C++11 mode, so the functions can be constexpr again. libstdc++-v3/ChangeLog: * include/std/array (array::operator[](size_t) const, array::front() const) (array::back() const) [__cplusplus == 201103]: Disable assertions. * testsuite/23_containers/array/element_access/constexpr_element_access.cc: Check for correct values. * testsuite/23_containers/array/tuple_interface/get_neg.cc: Adjust dg-error line numbers. * testsuite/23_containers/array/debug/constexpr_c++11.cc: New test.
-rw-r--r--libstdc++-v3/include/std/array6
-rw-r--r--libstdc++-v3/testsuite/23_containers/array/debug/constexpr_c++11.cc32
-rw-r--r--libstdc++-v3/testsuite/23_containers/array/element_access/constexpr_element_access.cc15
-rw-r--r--libstdc++-v3/testsuite/23_containers/array/tuple_interface/get_neg.cc6
4 files changed, 48 insertions, 11 deletions
diff --git a/libstdc++-v3/include/std/array b/libstdc++-v3/include/std/array
index 3c4c88a..8075099 100644
--- a/libstdc++-v3/include/std/array
+++ b/libstdc++-v3/include/std/array
@@ -192,7 +192,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
constexpr const_reference
operator[](size_type __n) const noexcept
{
+#if __cplusplus >= 201402L
__glibcxx_requires_subscript(__n);
+#endif
return _AT_Type::_S_ref(_M_elems, __n);
}
@@ -228,7 +230,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
constexpr const_reference
front() const noexcept
{
+#if __cplusplus >= 201402L
__glibcxx_requires_nonempty();
+#endif
return _AT_Type::_S_ref(_M_elems, 0);
}
@@ -242,7 +246,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
constexpr const_reference
back() const noexcept
{
+#if __cplusplus >= 201402L
__glibcxx_requires_nonempty();
+#endif
return _Nm ? _AT_Type::_S_ref(_M_elems, _Nm - 1)
: _AT_Type::_S_ref(_M_elems, 0);
}
diff --git a/libstdc++-v3/testsuite/23_containers/array/debug/constexpr_c++11.cc b/libstdc++-v3/testsuite/23_containers/array/debug/constexpr_c++11.cc
new file mode 100644
index 0000000..c8b3599
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/array/debug/constexpr_c++11.cc
@@ -0,0 +1,32 @@
+// { dg-options "-std=gnu++11 -D_GLIBCXX_DEBUG" }
+// { dg-do compile { target c++11 } }
+
+// Copyright (C) 2011-2020 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>
+
+void test01()
+{
+ // array
+ constexpr std::array<std::size_t, 6> a = { { 0, 55, 66, 99, 4115, 2 } };
+ constexpr auto v1 = a[1];
+ constexpr auto v2 = a.at(2);
+ constexpr auto v3 = a.front();
+ constexpr auto v4 = a.back();
+ static_assert( (v1 + v2 + v3 + v4) == (55 + 66 + 0 + 2), "" );
+}
diff --git a/libstdc++-v3/testsuite/23_containers/array/element_access/constexpr_element_access.cc b/libstdc++-v3/testsuite/23_containers/array/element_access/constexpr_element_access.cc
index c1dd905..037f6ea 100644
--- a/libstdc++-v3/testsuite/23_containers/array/element_access/constexpr_element_access.cc
+++ b/libstdc++-v3/testsuite/23_containers/array/element_access/constexpr_element_access.cc
@@ -19,14 +19,13 @@
#include <array>
-int main()
+void test01()
{
// array
- typedef std::array<std::size_t, 6> array_type;
- 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;
+ constexpr std::array<std::size_t, 6> a = { { 0, 55, 66, 99, 4115, 2 } };
+ constexpr auto v1 = a[1];
+ constexpr auto v2 = a.at(2);
+ constexpr auto v3 = a.front();
+ constexpr auto v4 = a.back();
+ static_assert( (v1 + v2 + v3 + v4) == (55 + 66 + 0 + 2), "" );
}
diff --git a/libstdc++-v3/testsuite/23_containers/array/tuple_interface/get_neg.cc b/libstdc++-v3/testsuite/23_containers/array/tuple_interface/get_neg.cc
index 88416cc..e287eef 100644
--- a/libstdc++-v3/testsuite/23_containers/array/tuple_interface/get_neg.cc
+++ b/libstdc++-v3/testsuite/23_containers/array/tuple_interface/get_neg.cc
@@ -26,6 +26,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 *-*-* } 357 }
-// { dg-error "static assertion failed" "" { target *-*-* } 365 }
-// { dg-error "static assertion failed" "" { target *-*-* } 373 }
+// { dg-error "static assertion failed" "" { target *-*-* } 363 }
+// { dg-error "static assertion failed" "" { target *-*-* } 371 }
+// { dg-error "static assertion failed" "" { target *-*-* } 379 }