From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21189 invoked by alias); 8 Sep 2014 09:33:54 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 21177 invoked by uid 89); 8 Sep 2014 09:33:53 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-we0-f182.google.com Received: from mail-we0-f182.google.com (HELO mail-we0-f182.google.com) (74.125.82.182) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Mon, 08 Sep 2014 09:33:52 +0000 Received: by mail-we0-f182.google.com with SMTP id w62so14753268wes.27 for ; Mon, 08 Sep 2014 02:33:49 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.194.221.74 with SMTP id qc10mr32773128wjc.39.1410168829863; Mon, 08 Sep 2014 02:33:49 -0700 (PDT) Received: by 10.194.20.69 with HTTP; Mon, 8 Sep 2014 02:33:49 -0700 (PDT) In-Reply-To: <5409C666.4050607@redhat.com> References: <5408988E.2060301@redhat.com> <5409C666.4050607@redhat.com> Date: Mon, 08 Sep 2014 09:33:00 -0000 Message-ID: Subject: Re: is portable aliasing possible in C++? From: Richard Biener To: Jason Merrill Cc: Jonathan Wakely , Andrew Haley , Andy Webber , gcc-help Content-Type: text/plain; charset=UTF-8 X-SW-Source: 2014-09/txt/msg00046.txt.bz2 On Fri, Sep 5, 2014 at 4:19 PM, Jason Merrill wrote: > On 09/04/2014 07:11 PM, Jonathan Wakely wrote: >> >> Placement new might work with GCC in practice as long as the buffer is >> correctly aligned and the type being constructed does not have >> non-trivial initialization. However, my reading of the standard is >> that after the placement new, if the object's members are not >> initialized then they have indeterminate values (not the values that >> were at those memory addresses already, even though that's likely to >> be what happens in practice). > > > I think that's a defect in the (non-normative) note in 5.3.4/17, which is > assuming that this follows from the rule in 8.5/12. But I don't think it > does, because in this case the storage has been initialized and therefore is > no longer indeterminate. > > So I think the placement new form is OK. Huh? Doesn't placement new end the lifetime of the object that resided at the address (by re-using memory) and start lifetime of a new object at that address? So how can the new object see the storage contents of the old object? GCC certainly doesn't support type-punning via placement new. As with all methods you might be lucky with recent enough GCC versions as if they see a must-alias they don't try to disambiguate further with TBAA. Richard. > Jason >