re PR libstdc++/58594 (std::make_shared does not accept const types as parameters)
authorJonathan Wakely <jwakely.gcc@gmail.com>
Wed, 2 Oct 2013 19:55:14 +0000 (19:55 +0000)
committerJonathan Wakely <redi@gcc.gnu.org>
Wed, 2 Oct 2013 19:55:14 +0000 (20:55 +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.

From-SVN: r203131

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/shared_ptr_base.h
libstdc++-v3/testsuite/20_util/shared_ptr/creation/58594.cc [new file with mode: 0644]

index 61c20a2..3041e87 100644 (file)
@@ -1,3 +1,10 @@
+2013-10-02  Jonathan Wakely  <jwakely.gcc@gmail.com>
+
+       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.
+
 2013-10-02  Tim Shen  <timshen91@gmail.com>
 
        * include/bits/regex_compiler.h
index fb19d08..f4bff77 100644 (file)
@@ -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 (file)
index 0000000..d1e3a7c
--- /dev/null
@@ -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>();
+}