User account creation filtered due to spam.

Bug 48398 - [4.6/4.7 Regression] [C++0x] std::unique_ptr<T, D> is broken when D::pointer is not T*
Summary: [4.6/4.7 Regression] [C++0x] std::unique_ptr<T, D> is broken when D::pointer ...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 4.6.0
: P3 normal
Target Milestone: 4.6.1
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2011-04-01 08:30 UTC by Takaya Saito
Modified: 2011-04-02 19:35 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2011-04-01 10:15:24


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Takaya Saito 2011-04-01 08:30:27 UTC
example:

------------------------------------------------------------

#include <memory>
#include <cassert>

struct my_deleter
{
  typedef int* pointer;
  
  void operator()( pointer p ) {
    delete p;
  }

};

int main()
{
  std::unique_ptr<void, my_deleter> p( new int() );

  assert( p.get() != 0 ); // invalid conversion from 'void*' to 'int*'
  p.reset(); // no matching function for call to 'swap( void*&, int*& )'
}

------------------------------------------------------------


proposed patch:

--- libstdc++-v3/include/bits/unique_ptr.h
+++ libstdc++-v3/include/bits/unique_ptr.h
@@ -100,7 +100,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	typedef decltype( __test<_Del>(0)) type;
       };
 
-      typedef std::tuple<_Tp*, _Dp>  	__tuple_type;
+      typedef std::tuple<typename _Pointer::type, _Dp>  	__tuple_type;
       __tuple_type 			_M_t;
 
     public:
Comment 1 Paolo Carlini 2011-04-01 09:24:53 UTC
Thanks.

Jon, both PR and patch seem straightforward to me, I would go ahead for mainline and 4_6-branch too. Just let me know if you have the time...
Comment 2 Jonathan Wakely 2011-04-01 10:15:24 UTC
yes, the patch looks correct to me and should go on the 4.6 branch as it's a regression caused by http://gcc.gnu.org/viewcvs?view=revision&revision=158682 when we started using deleter_type::pointer

Prior to that change this slight variation worked ok:

#include <memory>
#include <cassert>

struct my_deleter
{
  typedef int* pointer;

  void operator()( void* p ) {
    delete static_cast<pointer>(p);
  }

};

int main()
{
  std::unique_ptr<void, my_deleter> p( new int() );

  assert( p.get() != 0 ); // invalid conversion from 'void*' to 'int*'
  p.reset(); // no matching function for call to 'swap( void*&, int*& )'
}


I won't be at home to test and commit it until tomorrow though
Comment 3 Paolo Carlini 2011-04-01 10:21:59 UTC
Ah, ok, thanks then!
Comment 4 Jonathan Wakely 2011-04-02 15:34:05 UTC
Author: redi
Date: Sat Apr  2 15:34:01 2011
New Revision: 171889

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=171889
Log:
2011-04-02  Jonathan Wakely  <redi@gcc.gnu.org>

	PR libstdc++/48398
	* include/bits/unique_ptr.h (__tuple_type): Store pointer type.
	* testsuite/20_util/unique_ptr/modifiers/48398.cc: New.
	* testsuite/20_util/unique_ptr/requirements/pointer_type.cc: Remove
	unused parameter name.

Added:
    branches/gcc-4_6-branch/libstdc++-v3/testsuite/20_util/unique_ptr/modifiers/48398.cc
Modified:
    branches/gcc-4_6-branch/libstdc++-v3/ChangeLog
    branches/gcc-4_6-branch/libstdc++-v3/include/bits/unique_ptr.h
    branches/gcc-4_6-branch/libstdc++-v3/testsuite/20_util/unique_ptr/requirements/pointer_type.cc
Comment 5 Jonathan Wakely 2011-04-02 19:32:18 UTC
Author: redi
Date: Sat Apr  2 19:32:15 2011
New Revision: 171894

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=171894
Log:
2011-04-02  Jonathan Wakely  <redi@gcc.gnu.org>

	PR libstdc++/48398
	* include/bits/unique_ptr.h (__tuple_type): Store pointer type.
	* testsuite/20_util/unique_ptr/modifiers/48398.cc: New.
	* testsuite/20_util/unique_ptr/requirements/pointer_type.cc: Remove
	unused parameter name.

Added:
    trunk/libstdc++-v3/testsuite/20_util/unique_ptr/modifiers/48398.cc
Modified:
    trunk/libstdc++-v3/ChangeLog
    trunk/libstdc++-v3/include/bits/unique_ptr.h
    trunk/libstdc++-v3/testsuite/20_util/unique_ptr/requirements/pointer_type.cc
Comment 6 Jonathan Wakely 2011-04-02 19:35:13 UTC
fixed for 4.6.1 - thanks for the report