Blob Blame History Raw
From f65c57d9d2a4f535e36c96b7f563574634e46b02 Mon Sep 17 00:00:00 2001
From: Peter Dimov <pdimov@pdimov.com>
Date: Wed, 12 Nov 2014 19:04:29 +0200
Subject: [PATCH] Fix explicit instantiation regression

---
 include/boost/smart_ptr/shared_ptr.hpp |  2 +-
 test/Jamfile.v2                        |  2 ++
 test/array_fail_array_access.cpp       |  6 +++++-
 test/sp_explicit_inst_test.cpp         | 23 +++++++++++++++++++++++
 4 files changed, 31 insertions(+), 2 deletions(-)
 create mode 100644 test/sp_explicit_inst_test.cpp

diff --git a/include/boost/smart_ptr/shared_ptr.hpp b/include/boost/smart_ptr/shared_ptr.hpp
index 82ece8b..8be92ab 100644
--- a/boost/smart_ptr/shared_ptr.hpp
+++ b/boost/smart_ptr/shared_ptr.hpp
@@ -655,7 +655,7 @@ public:
         BOOST_ASSERT( px != 0 );
         BOOST_ASSERT( i >= 0 && ( i < boost::detail::sp_extent< T >::value || boost::detail::sp_extent< T >::value == 0 ) );
 
-        return px[ i ];
+        return static_cast< typename boost::detail::sp_array_access< T >::type >( px[ i ] );
     }
 
     element_type * get() const BOOST_NOEXCEPT
diff --git a/test/Jamfile.v2 b/test/Jamfile.v2
index 027367c..0b51eee 100644
--- a/libs/smart_ptr/test/Jamfile.v2
+++ b/libs/smart_ptr/test/Jamfile.v2
@@ -153,5 +153,7 @@ import testing ;
           [ run allocate_shared_array_throws_test.cpp ]
           [ run allocate_shared_array_esft_test.cpp ]
           [ run allocate_shared_array_args_test.cpp ]
+
+          [ compile sp_explicit_inst_test.cpp ]
         ;
 }
diff --git a/test/array_fail_array_access.cpp b/test/array_fail_array_access.cpp
index abfacbe..4f4e3f8 100644
--- a/libs/smart_ptr/test/array_fail_array_access.cpp
+++ b/libs/smart_ptr/test/array_fail_array_access.cpp
@@ -12,8 +12,12 @@ struct X
 {
 };
 
+template<class T> void f( T & /*t*/ )
+{
+}
+
 int main()
 {
     boost::shared_ptr<X> px( new X );
-    px[ 0 ];
+    f( px[ 0 ] );
 }
diff --git a/test/sp_explicit_inst_test.cpp b/test/sp_explicit_inst_test.cpp
new file mode 100644
index 0000000..d8de782
--- /dev/null
+++ b/libs/smart_ptr/test/sp_explicit_inst_test.cpp
@@ -0,0 +1,23 @@
+//
+// Explicit instantiations are reported to exist in user code
+//
+// Copyright (c) 2014 Peter Dimov
+//
+// Distributed under the Boost Software License, Version 1.0.
+// See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt
+//
+
+#include <boost/shared_ptr.hpp>
+
+template class boost::shared_ptr< int >;
+
+struct X
+{
+};
+
+template class boost::shared_ptr< X >;
+
+int main()
+{
+}
-- 
2.1.0