This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH 1/3] Introduce gdb::unique_ptr


On 10/10/2016 06:49 PM, Simon Marchi wrote:
> This is clearly way above my C++ skill level, I feel like I'm reading
> boost code.  

Oh, boost has a unique_ptr emulation, and _that_ one is almost
impenetrable.  ;-)  This version is trivial in comparison.  That said,
it has the advantage that is fully transparent on the "client" side,
for routine usage.  Other than std vs gdb namespace, that is.

> But since it's well encapsulated in a "support" file and
> mimics the standard behaviors, I think it's good.  I just hope the whole
> codebase won't end up lookup like this :).

Yeah.  This, just like the operator new patch, this is foundational work.
A smart pointer is the major gaping hole right now.  With this in place,
I expect that we'll add lots of uses like in patches #2 and #3, but don't
expect to need to touch the "library" code all that much or at all.

> 
> On 2016-10-10 12:46, Pedro Alves wrote:
>>  - support for all of 'ptr != NULL', 'ptr == NULL' and 'if (ptr)'
>>    using the safe bool idiom.
> 
> Since our coding style doesn't allow the "if (ptr)" form, is it possible
> to make it cause a compile error?

The point is that std::unique_ptr allows it, so I'd rather allow it in
C++03 as well, otherwise we'd potentially introduce unnoticed 
build errors when developing with GCC >= 6.

I found the need for that with patch #2 (expression_up).  As soon as
you convert a raw pointer to a smart pointer, all old code that
was working with the raw pointer is now going through the smart
pointer.  And it's that old code that surprisingly has the 
"if (ptr)" form in several places.

> 
>> +/* Base class of our unique_ptr emulation.  Contains code common to
>> +   both the unique_ptr<T, D> and unique_ptr<T[], D>.  */
>> +
>> +template<typename T, typename D>
>> +class unique_ptr_base : public safe_bool <unique_ptr_base<T, D> >
>> +{
>> +public:
>> +  typedef T *pointer;
> 
> pointer_type?

That's part of the std::unique_ptr interface:

  http://en.cppreference.com/w/cpp/memory/unique_ptr

Thanks,
Pedro Alves


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]