]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR libstdc++/87809 avoid invalid expressions in exception specifications
authorJonathan Wakely <jwakely@redhat.com>
Tue, 30 Oct 2018 14:49:43 +0000 (14:49 +0000)
committerJonathan Wakely <redi@gcc.gnu.org>
Tue, 30 Oct 2018 14:49:43 +0000 (14:49 +0000)
If the allocator isn't default constructible then checking if the
default constructor throws in an exception specification makes the
declaration invalid. Use the type trait instead.

PR libstdc++/87809
* include/bits/forward_list.h (_Fwd_list_impl::_Fwd_list_impl()): Use
trait in exception-specification instead of possibly invalid
expression.
* include/bits/stl_bvector.h (_Bvector_impl::_Bvector_impl()):
Likewise.
* include/bits/stl_list.h (_List_impl::_List_impl()): Likewise.
* include/bits/stl_vector.h (_Vector_impl::_Vector_impl()): Likewise.
* testsuite/23_containers/forward_list/cons/87809.cc: New test.
* testsuite/23_containers/list/cons/87809.cc: New test.
* testsuite/23_containers/vector/bool/cons/87809.cc: New test.
* testsuite/23_containers/vector/cons/87809.cc: New test.

From-SVN: r265626

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/forward_list.h
libstdc++-v3/include/bits/stl_bvector.h
libstdc++-v3/include/bits/stl_list.h
libstdc++-v3/include/bits/stl_vector.h
libstdc++-v3/testsuite/23_containers/forward_list/cons/87809.cc [new file with mode: 0644]
libstdc++-v3/testsuite/23_containers/list/cons/87809.cc [new file with mode: 0644]
libstdc++-v3/testsuite/23_containers/vector/bool/cons/87809.cc [new file with mode: 0644]
libstdc++-v3/testsuite/23_containers/vector/cons/87809.cc [new file with mode: 0644]

index 145eaa81edbfce6a4f3f67e1f3669d2a7433484c..5dc4295a1f697f563d101c17af58ff65b47cd3e9 100644 (file)
@@ -1,5 +1,18 @@
 2018-10-30  Jonathan Wakely  <jwakely@redhat.com>
 
+       PR libstdc++/87809
+       * include/bits/forward_list.h (_Fwd_list_impl::_Fwd_list_impl()): Use
+       trait in exception-specification instead of possibly invalid
+       expression.
+       * include/bits/stl_bvector.h (_Bvector_impl::_Bvector_impl()):
+       Likewise.
+       * include/bits/stl_list.h (_List_impl::_List_impl()): Likewise.
+       * include/bits/stl_vector.h (_Vector_impl::_Vector_impl()): Likewise.
+       * testsuite/23_containers/forward_list/cons/87809.cc: New test.
+       * testsuite/23_containers/list/cons/87809.cc: New test.
+       * testsuite/23_containers/vector/bool/cons/87809.cc: New test.
+       * testsuite/23_containers/vector/cons/87809.cc: New test.
+
        PR libstdc++/87784
        * include/tr2/dynamic_bitset (dynamic_bitset::push_back): When there
        are no unused bits in the last block, append a new block with the
index ebec3b5c818de34ad735d54f29bb815007c70055..1d01a54721b5b794fe56c282e9c11cfc5ea401c7 100644 (file)
@@ -293,7 +293,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
        _Fwd_list_node_base _M_head;
 
        _Fwd_list_impl()
-         noexcept( noexcept(_Node_alloc_type()) )
+         noexcept(is_nothrow_default_constructible<_Node_alloc_type>::value)
        : _Node_alloc_type(), _M_head()
        { }
 
index 19c16839cfaee3a4bd21f860d80f6e49ca3b2536..3752897272f2e009f60c368114874b57a6a66aa9 100644 (file)
@@ -473,8 +473,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
        : public _Bit_alloc_type, public _Bvector_impl_data
        {
        public:
-         _Bvector_impl()
-           _GLIBCXX_NOEXCEPT_IF( noexcept(_Bit_alloc_type()) )
+         _Bvector_impl() _GLIBCXX_NOEXCEPT_IF(
+               is_nothrow_default_constructible<_Bit_alloc_type>::value)
          : _Bit_alloc_type()
          { }
 
index 3544981698cc7ca4091dab4152e06faef9301ec9..cb8aa88d5485ffb6eaf6d73289327192d525d731 100644 (file)
@@ -372,7 +372,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
       {
        __detail::_List_node_header _M_node;
 
-       _List_impl() _GLIBCXX_NOEXCEPT_IF( noexcept(_Node_alloc_type()) )
+       _List_impl() _GLIBCXX_NOEXCEPT_IF(
+           is_nothrow_default_constructible<_Node_alloc_type>::value)
        : _Node_alloc_type()
        { }
 
index 40debd62396ed30402dd20963c5da43f3fb87a31..05f9b7ef6c3ace8ed20a953044f364240565cb6a 100644 (file)
@@ -125,7 +125,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
       struct _Vector_impl
        : public _Tp_alloc_type, public _Vector_impl_data
       {
-       _Vector_impl() _GLIBCXX_NOEXCEPT_IF( noexcept(_Tp_alloc_type()) )
+       _Vector_impl() _GLIBCXX_NOEXCEPT_IF(
+           is_nothrow_default_constructible<_Tp_alloc_type>::value)
        : _Tp_alloc_type()
        { }
 
diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/cons/87809.cc b/libstdc++-v3/testsuite/23_containers/forward_list/cons/87809.cc
new file mode 100644 (file)
index 0000000..cde9dff
--- /dev/null
@@ -0,0 +1,42 @@
+// Copyright (C) 2018 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/>.
+
+// { dg-do compile { target c++11 } }
+
+#include <forward_list>
+
+template <typename T>
+struct Alloc
+{
+  using value_type = T;
+
+  T* allocate(unsigned n);
+  void deallocate(T* p, unsigned n);
+
+  Alloc(int) { }
+
+  template<typename U>
+    Alloc(const Alloc<U>&) { }
+};
+
+template<typename T, typename U>
+  bool operator==(Alloc<T>, Alloc<U>) { return true; }
+template<typename T, typename U>
+  bool operator!=(Alloc<T>, Alloc<U>) { return false; }
+
+constexpr bool b
+  = std::is_default_constructible<std::forward_list<bool, Alloc<bool>>>::value;
diff --git a/libstdc++-v3/testsuite/23_containers/list/cons/87809.cc b/libstdc++-v3/testsuite/23_containers/list/cons/87809.cc
new file mode 100644 (file)
index 0000000..d7c5256
--- /dev/null
@@ -0,0 +1,42 @@
+// Copyright (C) 2018 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/>.
+
+// { dg-do compile { target c++11 } }
+
+#include <list>
+
+template <typename T>
+struct Alloc
+{
+  using value_type = T;
+
+  T* allocate(unsigned n);
+  void deallocate(T* p, unsigned n);
+
+  Alloc(int) { }
+
+  template<typename U>
+    Alloc(const Alloc<U>&) { }
+};
+
+template<typename T, typename U>
+  bool operator==(Alloc<T>, Alloc<U>) { return true; }
+template<typename T, typename U>
+  bool operator!=(Alloc<T>, Alloc<U>) { return false; }
+
+constexpr bool b
+  = std::is_default_constructible<std::list<bool, Alloc<bool>>>::value;
diff --git a/libstdc++-v3/testsuite/23_containers/vector/bool/cons/87809.cc b/libstdc++-v3/testsuite/23_containers/vector/bool/cons/87809.cc
new file mode 100644 (file)
index 0000000..b697abe
--- /dev/null
@@ -0,0 +1,42 @@
+// Copyright (C) 2018 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/>.
+
+// { dg-do compile { target c++11 } }
+
+#include <vector>
+
+template <typename T>
+struct Alloc
+{
+  using value_type = T;
+
+  T* allocate(unsigned n);
+  void deallocate(T* p, unsigned n);
+
+  Alloc(int) { }
+
+  template<typename U>
+    Alloc(const Alloc<U>&) { }
+};
+
+template<typename T, typename U>
+  bool operator==(Alloc<T>, Alloc<U>) { return true; }
+template<typename T, typename U>
+  bool operator!=(Alloc<T>, Alloc<U>) { return false; }
+
+constexpr bool b
+  = std::is_default_constructible<std::vector<bool, Alloc<bool>>>::value;
diff --git a/libstdc++-v3/testsuite/23_containers/vector/cons/87809.cc b/libstdc++-v3/testsuite/23_containers/vector/cons/87809.cc
new file mode 100644 (file)
index 0000000..0719933
--- /dev/null
@@ -0,0 +1,42 @@
+// Copyright (C) 2018 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/>.
+
+// { dg-do compile { target c++11 } }
+
+#include <vector>
+
+template <typename T>
+struct Alloc
+{
+  using value_type = T;
+
+  T* allocate(unsigned n);
+  void deallocate(T* p, unsigned n);
+
+  Alloc(int) { }
+
+  template<typename U>
+    Alloc(const Alloc<U>&) { }
+};
+
+template<typename T, typename U>
+  bool operator==(Alloc<T>, Alloc<U>) { return true; }
+template<typename T, typename U>
+  bool operator!=(Alloc<T>, Alloc<U>) { return false; }
+
+constexpr bool b
+  = std::is_default_constructible<std::vector<int, Alloc<int>>>::value;