Author Topic: CC no longer working for unique_ptr  (Read 16856 times)

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5267
Re: CC no longer working for unique_ptr
« Reply #15 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->


Offline Loaden

  • Lives here!
  • ****
  • Posts: 1014
Re: CC no longer working for unique_ptr
« Reply #16 on: August 31, 2011, 01:54:25 am »
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.

Offline Loaden

  • Lives here!
  • ****
  • Posts: 1014
Re: CC no longer working for unique_ptr
« Reply #17 on: August 31, 2011, 02:42:11 am »
I can't solved this issue. It's too complex.

Code: [Select]
/// 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:
Code: [Select]
      _Tp*
      operator->() const
      {

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

Every thing will works fine.
« Last Edit: August 31, 2011, 02:45:37 am by Loaden »

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5295
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: CC no longer working for unique_ptr
« Reply #18 on: September 01, 2011, 07:47:55 am »
Code: [Select]
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
Code: [Select]
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.
« Last Edit: September 01, 2011, 08:14:41 am by ollydbg »
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.