On 2017-04-12 22:27, Pedro Alves wrote:
This patch catches invalid initialization of non-POD types with
memset, at compile time.
Would it be possible to do something similar but to catch uses of
XNEW/XCNEW with types that need new? XNEW is defined as:
#define XNEW(T) ((T *) xmalloc (sizeof (T)))
I just tried this, and it seems to work well:
#define assert_pod(T) static_assert(std::is_pod<T>::value)
#undef XNEW
#define XNEW(T) ({ assert_pod(T); (T *) xmalloc (sizeof (T)); })
#undef XCNEW
#define XCNEW(T) ({ assert_pod(T); (T *) xcalloc (1, sizeof (T)); })
assuming the compiler knows about statement expressions.