* [patch] Fix std::shared_ptr FAILs with -fno-rtti
@ 2014-12-12 21:06 Jonathan Wakely
2014-12-13 0:45 ` Jonathan Wakely
0 siblings, 1 reply; 2+ messages in thread
From: Jonathan Wakely @ 2014-12-12 21:06 UTC (permalink / raw)
To: libstdc++, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 114 bytes --]
A couple of small fixes for shared_ptr tests that fail with -fno-rtti.
Tested x86_64-linux, committed to trunk.
[-- Attachment #2: patch.txt --]
[-- Type: text/x-patch, Size: 3105 bytes --]
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();
}
-
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [patch] Fix std::shared_ptr FAILs with -fno-rtti
2014-12-12 21:06 [patch] Fix std::shared_ptr FAILs with -fno-rtti Jonathan Wakely
@ 2014-12-13 0:45 ` Jonathan Wakely
0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Wakely @ 2014-12-13 0:45 UTC (permalink / raw)
To: libstdc++, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 297 bytes --]
On 12/12/14 21:06 +0000, Jonathan Wakely wrote:
>A couple of small fixes for shared_ptr tests that fail with -fno-rtti.
>
>Tested x86_64-linux, committed to trunk.
Huh, somehow I committed that when the new test wasn't even passing.
This fixes it properly. Tested again and committed to trunk.
[-- Attachment #2: patch.txt --]
[-- Type: text/x-patch, Size: 1775 bytes --]
commit b9fd3adf17cf8b03df10288f053615d7411d5fb5
Author: redi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Sat Dec 13 00:44:17 2014 +0000
PR libstdc++/58594
* include/bits/shared_ptr_base.h: Real fix for cv-qualified types.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@218698 138bc75d-0d04-0410-961f-82ee72b054a4
diff --git a/libstdc++-v3/include/bits/shared_ptr_base.h b/libstdc++-v3/include/bits/shared_ptr_base.h
index 3ef783f..ad68c23 100644
--- a/libstdc++-v3/include/bits/shared_ptr_base.h
+++ b/libstdc++-v3/include/bits/shared_ptr_base.h
@@ -1106,7 +1106,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _Alloc>
struct _Deleter
{
- void operator()(_Tp* __ptr)
+ void operator()(typename _Alloc::value_type* __ptr)
{
__allocated_ptr<_Alloc> __guard{ _M_alloc, __ptr };
allocator_traits<_Alloc>::destroy(_M_alloc, __guard.get());
@@ -1123,14 +1123,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
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();
+ auto __ptr = __guard.get();
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 2070. allocate_shared should use allocator_traits<A>::construct
- __traits::construct(__del._M_alloc, _M_ptr,
+ __traits::construct(__del._M_alloc, __ptr,
std::forward<_Args>(__args)...);
__guard = nullptr;
- __shared_count<_Lp> __count(_M_ptr, __del, __del._M_alloc);
+ __shared_count<_Lp> __count(__ptr, __del, __del._M_alloc);
_M_refcount._M_swap(__count);
+ _M_ptr = __ptr;
__enable_shared_from_this_helper(_M_refcount, _M_ptr, _M_ptr);
}
#endif
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-12-13 0:45 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-12 21:06 [patch] Fix std::shared_ptr FAILs with -fno-rtti Jonathan Wakely
2014-12-13 0:45 ` Jonathan Wakely
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).