diff mbox

Fix std::shared_ptr FAILs with -fno-rtti

Message ID 20141212210631.GQ3134@redhat.com
State New
Headers show

Commit Message

Jonathan Wakely Dec. 12, 2014, 9:06 p.m. UTC
A couple of small fixes for shared_ptr tests that fail with -fno-rtti.

Tested x86_64-linux, committed to trunk.
diff mbox

Patch

commit ec3619710af701b1030a6eb45862a41dc3e18ad8
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Fri Dec 12 16:17:45 2014 +0000

    	PR libstdc++/58594
    	* include/bits/shared_ptr_base.h: Cast away cv-quals.
    	* testsuite/20_util/shared_ptr/creation/58594-no-rtti.cc: New.
    	* testsuite/20_util/shared_ptr/creation/private.cc: Make allocator
    	rebindable so test passes with -fno-rtti.

diff --git a/libstdc++-v3/include/bits/shared_ptr_base.h b/libstdc++-v3/include/bits/shared_ptr_base.h
index 737a1a2..3ef783f 100644
--- a/libstdc++-v3/include/bits/shared_ptr_base.h
+++ b/libstdc++-v3/include/bits/shared_ptr_base.h
@@ -1120,7 +1120,7 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	: _M_ptr(), _M_refcount()
 	{
 	  typedef typename allocator_traits<_Alloc>::template
-	    rebind_traits<_Tp> __traits;
+	    rebind_traits<typename std::remove_cv<_Tp>::type> __traits;
 	  _Deleter<typename __traits::allocator_type> __del = { __a };
 	  auto __guard = std::__allocate_guarded(__del._M_alloc);
 	  _M_ptr = __guard.get();
diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/creation/58594-no-rtti.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/creation/58594-no-rtti.cc
new file mode 100644
index 0000000..2eb8b95
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/shared_ptr/creation/58594-no-rtti.cc
@@ -0,0 +1,27 @@ 
+// { dg-options "-std=gnu++11 -fno-rtti" }
+// { dg-do compile }
+
+// Copyright (C) 2014 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>
+
+// libstdc++/58594
+void test01()
+{
+  std::make_shared<const int>();
+}
diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/creation/private.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/creation/private.cc
index 46487bb..63ab555 100644
--- a/libstdc++-v3/testsuite/20_util/shared_ptr/creation/private.cc
+++ b/libstdc++-v3/testsuite/20_util/shared_ptr/creation/private.cc
@@ -37,8 +37,17 @@  public:
 };
 
 template<typename T>
-struct MyAlloc : std::allocator<Private>
+struct MyAlloc : std::allocator<T>
 {
+  template<typename U>
+    struct rebind { typedef MyAlloc<U> other; };
+
+  MyAlloc() = default;
+  MyAlloc(const MyAlloc&) = default;
+
+  template<typename U>
+    MyAlloc(const MyAlloc<U>&) { }
+
   void construct(T* p) { ::new((void*)p) T(); }
   void destroy(T* p) { p->~T(); }
 };
@@ -49,4 +58,3 @@  int main()
   auto p = std::allocate_shared<Private>(a);
   return p->get();
 }
-