From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 124246 invoked by alias); 24 Apr 2017 01:12:33 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 124233 invoked by uid 89); 24 Apr 2017 01:12:32 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.5 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_SOFTFAIL autolearn=no version=3.3.2 spammy= X-HELO: simark.ca Received: from simark.ca (HELO simark.ca) (158.69.221.121) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 24 Apr 2017 01:12:30 +0000 Received: by simark.ca (Postfix, from userid 33) id C7C9F1E4A4; Sun, 23 Apr 2017 21:12:30 -0400 (EDT) To: Pedro Alves Subject: Re: [PATCH 1/5] Poison non-POD memset & non-trivially-copyable memcpy/memmove X-PHP-Originating-Script: 33:rcube.php MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Mon, 24 Apr 2017 01:12:00 -0000 From: Simon Marchi Cc: gdb-patches@sourceware.org In-Reply-To: <1492050475-9238-2-git-send-email-palves@redhat.com> References: <1492050475-9238-1-git-send-email-palves@redhat.com> <1492050475-9238-2-git-send-email-palves@redhat.com> Message-ID: X-Sender: simon.marchi@polymtl.ca User-Agent: Roundcube Webmail/1.2.4 X-IsSubscribed: yes X-SW-Source: 2017-04/txt/msg00631.txt.bz2 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::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.