diff mbox

[v3] fix libstdc++/58594

Message ID CAH6eHdRi2wqRxfyEW2gtAufs+Gn=OXHL78wr4Mzr-0ivmx-ibQ@mail.gmail.com
State New
Headers show

Commit Message

Jonathan Wakely Oct. 2, 2013, 7:55 p.m. UTC
PR libstdc++/58594
        * include/bits/shared_ptr_base.h
        (_Sp_counted_ptr_inplace::_M_get_deleter()): Cast away cv-quals.
        * testsuite/20_util/shared_ptr/creation/58594.cc: New.

Tested x86_64-linux, committed to trunk
commit a58a4bea9475af3e3c44959aeab4b3ac48dc1af0
Author: Jonathan Wakely <jwakely.gcc@gmail.com>
Date:   Wed Oct 2 19:34:01 2013 +0100

    	PR libstdc++/58594
    	* include/bits/shared_ptr_base.h
    	(_Sp_counted_ptr_inplace::_M_get_deleter()): Cast away cv-quals.
    	* testsuite/20_util/shared_ptr/creation/58594.cc: New.
diff mbox

Patch

diff --git a/libstdc++-v3/include/bits/shared_ptr_base.h b/libstdc++-v3/include/bits/shared_ptr_base.h
index fb19d08..f4bff77 100644
--- a/libstdc++-v3/include/bits/shared_ptr_base.h
+++ b/libstdc++-v3/include/bits/shared_ptr_base.h
@@ -459,10 +459,10 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
       _M_get_deleter(const std::type_info& __ti) noexcept
       {
 #ifdef __GXX_RTTI
-	return __ti == typeid(_Sp_make_shared_tag) ? _M_ptr() : nullptr;
-#else
-        return nullptr;
+	if (__ti == typeid(_Sp_make_shared_tag))
+	  return const_cast<typename remove_cv<_Tp>::type*>(_M_ptr());
 #endif
+	return nullptr;
       }
 
     private:
diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/creation/58594.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/creation/58594.cc
new file mode 100644
index 0000000..d1e3a7c
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/shared_ptr/creation/58594.cc
@@ -0,0 +1,27 @@ 
+// { dg-options "-std=gnu++11" }
+// { dg-do compile }
+
+// 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>
+
+// libstdc++/58594
+void test01()
+{
+  std::make_shared<const int>();
+}