News:

As usual while waiting for the next release - don't forget to check the nightly builds in the forum.

Main Menu

CC no longer working for unique_ptr

Started by killerbot, August 29, 2011, 11:34:27 PM

Previous topic - Next topic

killerbot

I can confirm that the first problem is solved : foo.

But the second one still fails : bar->


Loaden

Quote from: killerbot on August 30, 2011, 08:25:59 PM
I can confirm that the first problem is solved : foo.

But the second one still fails : bar->
About the second issue: shared_ptr<Test> and auto_ptr<Test> works well.
So, There should has some thing changed with unique_ptr.

Loaden

#17
I can't solved this issue. It's too complex.

/// 20.7.12.2 unique_ptr for single objects.
 template <typename _Tp, typename _Dp = default_delete<_Tp> >
   class unique_ptr
   {
     // use SFINAE to determine whether _Del::pointer exists
     class _Pointer
     {
template<typename _Up>
 static typename _Up::pointer __test(typename _Up::pointer*);

template<typename _Up>
 static _Tp* __test(...);

typedef typename remove_reference<_Dp>::type _Del;

     public:
typedef decltype( __test<_Del>(0)) type;
     };

     typedef std::tuple<typename _Pointer::type, _Dp>  __tuple_type;
     __tuple_type                                      _M_t;

   public:
     typedef typename _Pointer::type   pointer;
...
     pointer
     operator->() const
     {

_GLIBCXX_DEBUG_ASSERT(get() != pointer());
return get();
     }


See: typedef typename _Pointer::type   pointer;

I don't understood what's the meaning.

If change to:
      _Tp*
     operator->() const
     {

_GLIBCXX_DEBUG_ASSERT(get() != pointer());
return get();
     }


Every thing will works fine.

ollydbg

#18
typedef typename _Pointer::type   pointer;
we should resolve the actual type of the string "_Pointer::type".

As the definition of the embedded class _Pointer, "_Pointer::type" is actually a type from the "decltype operator" deduced from the expression "__test<_Del>(0)".

Then "__test<_Del>(0)" is a function calling expression defined by
template<typename _Up>
 static _Tp* __test(...);


So, it's actual type is "_Tp*".

As a conclusion: C++'s type-deduction mechanism is heaven for programmer, but it is the hell for compiler/parser writer. :D, each step should involve the symbol table check and semantics check.
I don't think it can be implemented in CC, it was too complex.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.