public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
From: Aldy Hernandez <aldyh@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org
Subject: [gcc/devel/ranger] libstdc++: make polymorphic_allocator throw consistent type (LWG 3237)
Date: Wed, 17 Jun 2020 19:01:46 +0000 (GMT)	[thread overview]
Message-ID: <20200617190146.24E203954422@sourceware.org> (raw)

https://gcc.gnu.org/g:e89100ef2efcf2bb1f1af1bdd81a1035d78f3fa4

commit e89100ef2efcf2bb1f1af1bdd81a1035d78f3fa4
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed Feb 19 15:21:31 2020 +0000

    libstdc++: make polymorphic_allocator throw consistent type (LWG 3237)
    
            * include/std/memory_resource (polymorphic_allocator::allocate)
            (polymorphic_allocator::allocate_object): Change type of exception to
            bad_array_new_length (LWG 3237).
            * testsuite/20_util/polymorphic_allocator/lwg3237.cc: New test.

Diff:
---
 libstdc++-v3/ChangeLog                             |  5 ++
 libstdc++-v3/include/std/memory_resource           |  4 +-
 .../20_util/polymorphic_allocator/lwg3237.cc       | 55 ++++++++++++++++++++++
 3 files changed, 62 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index bc4ce773f1e..067cf8343f6 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,5 +1,10 @@
 2020-02-19  Jonathan Wakely  <jwakely@redhat.com>
 
+	* include/std/memory_resource (polymorphic_allocator::allocate)
+	(polymorphic_allocator::allocate_object): Change type of exception to
+	bad_array_new_length (LWG 3237).
+	* testsuite/20_util/polymorphic_allocator/lwg3237.cc: New test.
+
 	* include/std/type_traits (__cpp_lib_unwrap_ref): Define (LWG 3348).
 	* include/std/version (__cpp_lib_unwrap_ref): Likewise.
 	* testsuite/20_util/unwrap_reference/1.cc: Check macro.
diff --git a/libstdc++-v3/include/std/memory_resource b/libstdc++-v3/include/std/memory_resource
index 73f77bdcadf..74683c5267f 100644
--- a/libstdc++-v3/include/std/memory_resource
+++ b/libstdc++-v3/include/std/memory_resource
@@ -167,7 +167,7 @@ namespace pmr
       __attribute__((__returns_nonnull__))
       {
 	if (__n > (__detail::__int_limits<size_t>::max() / sizeof(_Tp)))
-	  std::__throw_bad_alloc();
+	  _GLIBCXX_THROW_OR_ABORT(bad_array_new_length());
 	return static_cast<_Tp*>(_M_resource->allocate(__n * sizeof(_Tp),
 						       alignof(_Tp)));
       }
@@ -193,7 +193,7 @@ namespace pmr
 	allocate_object(size_t __n = 1)
 	{
 	  if ((__detail::__int_limits<size_t>::max() / sizeof(_Up)) < __n)
-	    __throw_length_error("polymorphic_allocator::allocate_object");
+	    _GLIBCXX_THROW_OR_ABORT(bad_array_new_length());
 	  return static_cast<_Up*>(allocate_bytes(__n * sizeof(_Up),
 						  alignof(_Up)));
 	}
diff --git a/libstdc++-v3/testsuite/20_util/polymorphic_allocator/lwg3237.cc b/libstdc++-v3/testsuite/20_util/polymorphic_allocator/lwg3237.cc
new file mode 100644
index 00000000000..350f5ac9c95
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/polymorphic_allocator/lwg3237.cc
@@ -0,0 +1,55 @@
+// Copyright (C) 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/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do run { target c++2a } }
+
+#include <memory_resource>
+#include <testsuite_hooks.h>
+
+struct large { alignas(1024) int i; };
+
+void
+test01()
+{
+  std::pmr::polymorphic_allocator<large> a;
+  large* p = nullptr;
+  try
+  {
+    p = a.allocate(std::size_t(-1) / 256);
+    VERIFY( false );
+  }
+  catch (const std::bad_array_new_length&)
+  {
+  }
+
+  std::pmr::polymorphic_allocator<int> a2;
+  try
+  {
+    p = a2.allocate_object<large>(std::size_t(-1) / 256);
+    VERIFY( false );
+  }
+  catch (const std::bad_array_new_length&)
+  {
+  }
+}
+
+int
+main()
+{
+  test01();
+}


                 reply	other threads:[~2020-06-17 19:01 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200617190146.24E203954422@sourceware.org \
    --to=aldyh@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    --cc=libstdc++-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).