aboutsummaryrefslogtreecommitdiff
path: root/gdb/common
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/common')
-rw-r--r--gdb/common/poison.h31
-rw-r--r--gdb/common/traits.h8
2 files changed, 38 insertions, 1 deletions
diff --git a/gdb/common/poison.h b/gdb/common/poison.h
index c98d2b3..ddab2c1 100644
--- a/gdb/common/poison.h
+++ b/gdb/common/poison.h
@@ -21,6 +21,7 @@
#define COMMON_POISON_H
#include "traits.h"
+#include "obstack.h"
/* Poison memset of non-POD types. The idea is catching invalid
initialization of non-POD structs that is easy to be introduced as
@@ -88,7 +89,11 @@ void *memmove (D *dest, const S *src, size_t n) = delete;
objects that require new/delete. */
template<typename T>
-using IsMallocable = std::is_pod<T>;
+#if HAVE_IS_TRIVIALLY_CONSTRUCTIBLE
+using IsMallocable = std::is_trivially_constructible<T>;
+#else
+using IsMallocable = std::true_type;
+#endif
template<typename T>
using IsFreeable = gdb::Or<std::is_trivially_destructible<T>, std::is_void<T>>;
@@ -216,4 +221,28 @@ non-POD data type.");
#undef XRESIZEVAR
#define XRESIZEVAR(T, P, S) xresizevar<T> (P, S)
+template<typename T>
+static T *
+xobnew (obstack *ob)
+{
+ static_assert (IsMallocable<T>::value, "Trying to use XOBNEW with a \
+non-POD data type.");
+ return XOBNEW (ob, T);
+}
+
+#undef XOBNEW
+#define XOBNEW(O, T) xobnew<T> (O)
+
+template<typename T>
+static T *
+xobnewvec (obstack *ob, size_t n)
+{
+ static_assert (IsMallocable<T>::value, "Trying to use XOBNEWVEC with a \
+non-POD data type.");
+ return XOBNEWVEC (ob, T, n);
+}
+
+#undef XOBNEWVEC
+#define XOBNEWVEC(O, T, N) xobnewvec<T> (O, N)
+
#endif /* COMMON_POISON_H */
diff --git a/gdb/common/traits.h b/gdb/common/traits.h
index d9e6839..070ef15 100644
--- a/gdb/common/traits.h
+++ b/gdb/common/traits.h
@@ -33,6 +33,14 @@
# define HAVE_IS_TRIVIALLY_COPYABLE 1
#endif
+/* HAVE_IS_TRIVIALLY_CONSTRUCTIBLE is defined as 1 iff
+ std::is_trivially_constructible is available. GCC only implemented it
+ in GCC 5. */
+#if (__has_feature(is_trivially_constructible) \
+ || (defined __GNUC__ && __GNUC__ >= 5))
+# define HAVE_IS_TRIVIALLY_COPYABLE 1
+#endif
+
namespace gdb {
/* Pre C++14-safe (CWG 1558) version of C++17's std::void_t. See