Allow gdb::unique_xmalloc_ptr<T[]>
authorPedro Alves <palves@redhat.com>
Thu, 10 Aug 2017 13:18:02 +0000 (14:18 +0100)
committerPedro Alves <palves@redhat.com>
Thu, 10 Aug 2017 13:18:02 +0000 (14:18 +0100)
commite7c9de26788dee7a620ea9cdabd7466fb07639c4
treeeeebed47b13e38c0a0c89b4da7a18bf738b3a875
parentca6f2be7f6bc638fd4fad48def1fae4ae4d7906e
Allow gdb::unique_xmalloc_ptr<T[]>

Currently, if you try to use the array version of
gdb::unique_xmalloc_ptr (i.e., std::unique_ptr) in order to have
access to operator[], like:

  gdb::unique_xmalloc_ptr<char[]> buf ((char *) xmalloc (10));
  return buf[0];

then the build fails, like:

  /usr/include/c++/5.3.1/bits/unique_ptr.h: In instantiation of ‘std::unique_ptr<_Tp [], _Dp>::~unique_ptr() [with _Tp = char; _Dp = gdb::xfree_deleter<char []>]’:
  main.c:30:61:   required from here
  /usr/include/c++/5.3.1/bits/unique_ptr.h:484:17: error: no match for call to ‘(std::unique_ptr<char [], gdb::xfree_deleter<char []> >::deleter_type {aka gdb::xfree_deleter<char []>}) (char*&)’
      get_deleter()(__ptr);
   ^
  In file included from src/gdb/common/common-defs.h:92:0,
   from src/gdb/defs.h:28,
   from src/gdb/main.c:20:
  src/gdb/common/gdb_unique_ptr.h:34:8: note: candidate: void gdb::xfree_deleter<T>::operator()(T*) const [with T = char []]
     void operator() (T *ptr) const { xfree (ptr); }
  ^
  src/gdb/common/gdb_unique_ptr.h:34:8: note:   no known conversion for argument 1 from ‘char*’ to ‘char (*)[]’
  Makefile:1911: recipe for target 'main.o' failed
  make: *** [main.o] Error 1

The problem is that we're missing an xfree_deleter specialization for
arrays.

gdb/ChangeLog:
2017-08-10  Pedro Alves  <palves@redhat.com>

* common/gdb_unique_ptr.h (xfree_deleter<T[]>): Define.
gdb/ChangeLog
gdb/common/gdb_unique_ptr.h
This page took 0.027 seconds and 4 git commands to generate.