diff mbox

PR libstdc++/79467 use lvalues in is_callable check

Message ID 20170211211111.GA4325@redhat.com
State New
Headers show

Commit Message

Jonathan Wakely Feb. 11, 2017, 9:11 p.m. UTC
These new static assertions fail if the deleter insists on lvalues (I
don't know why somebody would do that, but it caused a build failure
for fuse-encfs). Since the deleter is invoked as an lvalue and passed
an lvalue, this makes the assertion check the right thing.

	PR libstdc++/79467
	* include/bits/shared_ptr_base.h (__shared_ptr(_Yp*, _Deleter))
	(__shared_ptr(_Yp*, _Deleter, _Alloc)): Use lvalue types in
	__is_callable check.
	* testsuite/20_util/shared_ptr/cons/79467.cc: New.

Tested powerpc64le-linux, committed to trunk.
commit f3bca8b74ec018e5c7f0c8362b8d119df95e31f3
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Sat Feb 11 21:07:01 2017 +0000

    PR libstdc++/79467 use lvalues in is_callable check
    
    	PR libstdc++/79467
    	* include/bits/shared_ptr_base.h (__shared_ptr(_Yp*, _Deleter))
    	(__shared_ptr(_Yp*, _Deleter, _Alloc)): Use lvalue types in
    	__is_callable check.
    	* testsuite/20_util/shared_ptr/cons/79467.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 3b8a5c7..770a094 100644
--- a/libstdc++-v3/include/bits/shared_ptr_base.h
+++ b/libstdc++-v3/include/bits/shared_ptr_base.h
@@ -1085,7 +1085,7 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	__shared_ptr(_Yp* __p, _Deleter __d)
 	: _M_ptr(__p), _M_refcount(__p, __d)
 	{
-	  static_assert(__is_callable<_Deleter(_Yp*)>::value,
+	  static_assert(__is_callable<_Deleter&(_Yp*&)>::value,
 	      "deleter expression d(p) is well-formed");
 	  _M_enable_shared_from_this_with(__p);
 	}
@@ -1095,7 +1095,7 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	__shared_ptr(_Yp* __p, _Deleter __d, _Alloc __a)
 	: _M_ptr(__p), _M_refcount(__p, __d, std::move(__a))
 	{
-	  static_assert(__is_callable<_Deleter(_Yp*)>::value,
+	  static_assert(__is_callable<_Deleter&(_Yp*&)>::value,
 	      "deleter expression d(p) is well-formed");
 	  _M_enable_shared_from_this_with(__p);
 	}
diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/cons/79467.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/79467.cc
new file mode 100644
index 0000000..bcf9654
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/79467.cc
@@ -0,0 +1,27 @@ 
+// Copyright (C) 2017 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/>.
+
+// { dg-do compile { target c++11 } }
+
+#include <memory>
+
+struct D {
+  void operator()(int*&) & {} // PR libstdc++/79467
+};
+
+std::shared_ptr<int> p(new int, D());
+std::shared_ptr<int> q(new int, D(), std::allocator<int>());