summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2017-05-11 14:21:07 +0100
committerJonathan Wakely <redi@gcc.gnu.org>2017-05-11 14:21:07 +0100
commitf8cba3aaaef329e00f8af4364765274205402be9 (patch)
tree764714d31d91c426d61f6a43b855c705c688f52e /libstdc++-v3/testsuite
parent29b871ec5e1da82a58a6f58b575395dd07ff0050 (diff)
downloadgcc-f8cba3aaaef329e00f8af4364765274205402be9.tar.gz
PR libstdc++/80285 optimize std::make_shared for -fno-rtti
PR libstdc++/80285 * include/bits/shared_ptr_base.h (_Sp_make_shared_tag::_S_ti): Define function to get unique fake std::type_info reference. (_Sp_counted_ptr_inplace::_M_get_deleter) [!__cpp_rtti]: Compare to _S_ti() fake reference. (__shared_ptr(_Sp_make_shared_tag, const Alloc&, Args&&...)): Share single implementation with or without RTTI enable. [!__cpp_rtti]: Pass fake reference to _M_get_deleter. * testsuite/20_util/shared_ptr/creation/alloc.cc: Change expected allocation and deallocation counts. * testsuite/20_util/shared_ptr/creation/single_allocation.cc: New. * testsuite/20_util/shared_ptr/creation/single_allocation_no_rtti.cc: New. From-SVN: r247905
Diffstat (limited to 'libstdc++-v3/testsuite')
-rw-r--r--libstdc++-v3/testsuite/20_util/shared_ptr/creation/alloc.cc6
-rw-r--r--libstdc++-v3/testsuite/20_util/shared_ptr/creation/single_allocation.cc55
-rw-r--r--libstdc++-v3/testsuite/20_util/shared_ptr/creation/single_allocation_no_rtti.cc56
3 files changed, 114 insertions, 3 deletions
diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/creation/alloc.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/creation/alloc.cc
index b17387f11bc..7e53e41a72f 100644
--- a/libstdc++-v3/testsuite/20_util/shared_ptr/creation/alloc.cc
+++ b/libstdc++-v3/testsuite/20_util/shared_ptr/creation/alloc.cc
@@ -63,7 +63,7 @@ test01()
VERIFY( p1.get() != 0 );
VERIFY( p1.use_count() == 1 );
VERIFY( A::ctor_count == 1 );
- VERIFY( tracker_allocator_counter::get_allocation_count() > 0 );
+ VERIFY( tracker_allocator_counter::get_allocation_count() > sizeof(A) );
}
VERIFY( A::ctor_count == A::dtor_count );
VERIFY( tracker_allocator_counter::get_allocation_count()
@@ -79,12 +79,12 @@ test02()
p1 = std::allocate_shared<A>(tracker_allocator<A>(), 1);
VERIFY( A::ctor_count == 1 );
- VERIFY( tracker_allocator_counter::get_allocation_count() > 0 );
+ VERIFY( tracker_allocator_counter::get_allocation_count() > sizeof(A) );
p1 = std::allocate_shared<A>(tracker_allocator<A>(), 1, 2.0);
VERIFY( A::ctor_count == 2 );
VERIFY( A::dtor_count == 1 );
- VERIFY( tracker_allocator_counter::get_deallocation_count() > 0 );
+ VERIFY( tracker_allocator_counter::get_deallocation_count() > sizeof(A) );
p1 = std::allocate_shared<A>(tracker_allocator<A>(), 1, 2.0, '3');
VERIFY( A::ctor_count == 3 );
diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/creation/single_allocation.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/creation/single_allocation.cc
new file mode 100644
index 00000000000..51b6b1bc751
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/shared_ptr/creation/single_allocation.cc
@@ -0,0 +1,55 @@
+// Copyright (C) 2017 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 run { target c++11 } }
+
+#include <memory>
+#include <testsuite_hooks.h>
+
+int counter = 0;
+
+template<typename T>
+struct Alloc : std::allocator<T>
+{
+ template<typename U>
+ struct rebind { using other = Alloc<U>; };
+
+ Alloc() = default;
+
+ template<typename U>
+ Alloc(const Alloc<U>&) { }
+
+ T* allocate(std::size_t n)
+ {
+ ++counter;
+ return std::allocator<T>::allocate(n);
+ }
+};
+
+
+void
+test01()
+{
+ std::allocate_shared<int>(Alloc<int>());
+ VERIFY( counter == 1 );
+}
+
+int
+main()
+{
+ test01();
+}
diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/creation/single_allocation_no_rtti.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/creation/single_allocation_no_rtti.cc
new file mode 100644
index 00000000000..ba94f3cb90e
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/shared_ptr/creation/single_allocation_no_rtti.cc
@@ -0,0 +1,56 @@
+// Copyright (C) 2017 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 "-fno-rtti" }
+// { dg-do run { target c++11 } }
+
+#include <memory>
+#include <testsuite_hooks.h>
+
+int counter = 0;
+
+template<typename T>
+struct Alloc : std::allocator<T>
+{
+ template<typename U>
+ struct rebind { using other = Alloc<U>; };
+
+ Alloc() = default;
+
+ template<typename U>
+ Alloc(const Alloc<U>&) { }
+
+ T* allocate(std::size_t n)
+ {
+ ++counter;
+ return std::allocator<T>::allocate(n);
+ }
+};
+
+
+void
+test01()
+{
+ std::allocate_shared<int>(Alloc<int>());
+ VERIFY( counter == 1 );
+}
+
+int
+main()
+{
+ test01();
+}