This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[pushed] Allow gdb::unique_xmalloc_ptr<T[]>
- From: Pedro Alves <palves at redhat dot com>
- To: gdb-patches at sourceware dot org
- Date: Thu, 10 Aug 2017 14:21:30 +0100
- Subject: [pushed] Allow gdb::unique_xmalloc_ptr<T[]>
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=palves at redhat dot com
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 316B868A99
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 | 4 ++++
gdb/common/gdb_unique_ptr.h | 7 +++++++
2 files changed, 11 insertions(+)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 9918af1..f670f99 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,7 @@
+2017-08-10 Pedro Alves <palves@redhat.com>
+
+ * common/gdb_unique_ptr.h (xfree_deleter<T[]>): Define.
+
2017-08-09 John Baldwin <jhb@FreeBSD.org>
* fbsd-nat.c (struct fbsd_fork_info): Remove.
diff --git a/gdb/common/gdb_unique_ptr.h b/gdb/common/gdb_unique_ptr.h
index 4faadaf..34c993c 100644
--- a/gdb/common/gdb_unique_ptr.h
+++ b/gdb/common/gdb_unique_ptr.h
@@ -34,6 +34,13 @@ struct xfree_deleter
void operator() (T *ptr) const { xfree (ptr); }
};
+/* Same, for arrays. */
+template <typename T>
+struct xfree_deleter<T[]>
+{
+ void operator() (T *ptr) const { xfree (ptr); }
+};
+
/* Import the standard unique_ptr to our namespace with a custom
deleter. */
--
2.5.5