aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/20_util
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely.gcc@gmail.com>2013-10-08 12:33:37 +0000
committerJonathan Wakely <redi@gcc.gnu.org>2013-10-08 13:33:37 +0100
commit61bf02e007ceaaa81f92a9e10372303816955ba5 (patch)
tree9ae99d30df85db39801dab11898c312ec74fccfe /libstdc++-v3/testsuite/20_util
parent481d1b81534c70122187f38c26d6a19db587528f (diff)
downloadgcc-61bf02e007ceaaa81f92a9e10372303816955ba5.zip
gcc-61bf02e007ceaaa81f92a9e10372303816955ba5.tar.gz
gcc-61bf02e007ceaaa81f92a9e10372303816955ba5.tar.bz2
re PR libstdc++/58659 (Construction of shared_ptr from unique_ptr mismatches new/delete and std::allocator for __shared_ptr_count)
PR libstdc++/58659 * include/bits/shared_ptr_base.h (__shared_count::__shared_count(P,D)): Delegate to constructor taking allocator. (__shared_count::_S_create_from_up): Inline into ... (__shared_count::__shared_count(unique_ptr<Y,D>&&): Here. Use std::conditional instead of constrained overloads. Allocate memory using the allocator type that will be used for deallocation. * testsuite/20_util/shared_ptr/cons/58659.cc: New. * testsuite/20_util/shared_ptr/cons/43820_neg.cc: Adjust. From-SVN: r203274
Diffstat (limited to 'libstdc++-v3/testsuite/20_util')
-rw-r--r--libstdc++-v3/testsuite/20_util/shared_ptr/cons/43820_neg.cc2
-rw-r--r--libstdc++-v3/testsuite/20_util/shared_ptr/cons/58659.cc69
2 files changed, 70 insertions, 1 deletions
diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/cons/43820_neg.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/43820_neg.cc
index b6d1009..fd2a677 100644
--- a/libstdc++-v3/testsuite/20_util/shared_ptr/cons/43820_neg.cc
+++ b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/43820_neg.cc
@@ -32,7 +32,7 @@ void test01()
{
X* px = 0;
std::shared_ptr<X> p1(px); // { dg-error "here" }
- // { dg-error "incomplete" "" { target *-*-* } 807 }
+ // { dg-error "incomplete" "" { target *-*-* } 778 }
std::shared_ptr<X> p9(ap()); // { dg-error "here" }
// { dg-error "incomplete" "" { target *-*-* } 307 }
diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/cons/58659.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/58659.cc
new file mode 100644
index 0000000..5e7c730
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/58659.cc
@@ -0,0 +1,69 @@
+// { dg-options "-std=gnu++11" }
+
+// Copyright (C) 2013 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 <memory>
+#include <testsuite_hooks.h>
+
+struct X { };
+
+using spcd = std::_Sp_counted_deleter<X*, std::default_delete<X>,
+std::allocator<void>, std::__default_lock_policy>;
+
+namespace std
+{
+ template<>
+ struct allocator<spcd>
+ {
+ using value_type = spcd;
+
+ allocator() = default;
+
+ template<typename U>
+ allocator(const allocator<U>&) { }
+
+ value_type* allocate(size_t n)
+ {
+ if (n != 1)
+ throw bad_alloc();
+ allocated = true;
+ return static_cast<value_type*>((void*)(storage));
+ }
+
+ void deallocate(value_type* p, size_t n)
+ {
+ if (n != 1 || p != (void*)storage || !allocated)
+ abort();
+ allocated = false;
+ }
+
+ static char storage[sizeof(spcd)];
+ static bool allocated;
+ };
+
+ char allocator<spcd>::storage[];
+ bool allocator<spcd>::allocated = false;
+}
+
+int main()
+{
+ std::shared_ptr<X> s( std::unique_ptr<X>(new X) );
+ VERIFY( std::allocator<spcd>::allocated );
+ s.reset();
+ VERIFY( !std::allocator<spcd>::allocated );
+}