From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10619 invoked by alias); 7 Sep 2013 21:08:39 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 10609 invoked by uid 89); 7 Sep 2013 21:08:38 -0000 Received: from mail2-relais-roc.national.inria.fr (HELO mail2-relais-roc.national.inria.fr) (192.134.164.83) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (CAMELLIA256-SHA encrypted) ESMTPS; Sat, 07 Sep 2013 21:08:38 +0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.7 required=5.0 tests=AWL,BAYES_00,KHOP_THREADED,RDNS_NONE autolearn=no version=3.3.2 X-HELO: mail2-relais-roc.national.inria.fr Received: from stedding.saclay.inria.fr ([193.55.250.194]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES128-SHA; 07 Sep 2013 23:08:33 +0200 Received: from glisse (helo=localhost) by stedding.saclay.inria.fr with local-esmtp (Exim 4.80) (envelope-from ) id 1VIPk9-0001ED-Ol; Sat, 07 Sep 2013 23:08:33 +0200 Date: Sat, 07 Sep 2013 21:37:00 -0000 From: Marc Glisse To: Mike Stump cc: "gcc-patches@gcc.gnu.org" Subject: Re: operator new returns nonzero In-Reply-To: Message-ID: References: <7209CCD2-9BA5-4CD2-8A2B-9DEF2D2C88D2@comcast.net> <8314FBDA-0F5E-4772-A7D6-49319390170B@comcast.net> User-Agent: Alpine 2.02 (DEB 1266 2009-07-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-SW-Source: 2013-09/txt/msg00499.txt.bz2 On Sat, 7 Sep 2013, Marc Glisse wrote: > On Sat, 7 Sep 2013, Mike Stump wrote: > >> Can this throw: >> >> void *operator new (long unsigned int s) { >> return 0; >> } >> >> ? Is this allowed to return 0? > > I think using this function is illegal. It isn't marked noexcept, so it isn't > allowed to return 0. And if I compile your code with gcc, I get nice warnings (though I get them twice and the column number is not so good): m.cc: In function 'void* operator new(long unsigned int)': m.cc:2:12: warning: 'operator new' must not return NULL unless it is declared 'throw()' (or -fcheck-new is in effect) [enabled by default] return 0; ^ m.cc: At global scope: m.cc:1:7: warning: unused parameter 's' [-Wunused-parameter] void *operator new (long unsigned int s) { ^ -- Marc Glisse