From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1633 invoked by alias); 23 May 2007 19:10:32 -0000 Received: (qmail 1594 invoked by alias); 23 May 2007 19:10:17 -0000 Date: Wed, 23 May 2007 19:10:00 -0000 Message-ID: <20070523191017.1593.qmail@sourceware.org> X-Bugzilla-Reason: CC References: Subject: [Bug libstdc++/29286] [4.0/4.1/4.2/4.3 Regression] placement new does not change the dynamic type as it should In-Reply-To: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "mark at codesourcery dot com" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2007-05/txt/msg02059.txt.bz2 ------- Comment #136 from mark at codesourcery dot com 2007-05-23 20:10 ------- Subject: Re: [4.0/4.1/4.2/4.3 Regression] placement new does not change the dynamic type as it should rguenth at gcc dot gnu dot org wrote: > ------- Comment #134 from rguenth at gcc dot gnu dot org 2007-05-23 19:54 ------- > But using a union for type-punning is a gcc extension (and of course the > extension > is only for access through the union), so with strict C99/C++ semantics we can > avoid reloading d[i-1] even if a and d were in the same union because the code > would then be invalid. Gaby's claim, as I understand it, is that writing to a union member, even through a pointer, rather than directly through the union, is valid, and activates that part of the union. So, it is not a GCC extension. For code like: a[i] = i; d[i] = d[i-1] + a[i]; I guess you can argue that a[i] does not alias d[i-1], even in Gaby's model, because a[i] is written to right before the access to d[i-1]. But, you don't know that a[m] doesn't alias d[n] for arbitrary m and n. So, it's easy to create variations on the case I posted that can't be optimized, if you agree to Gaby's model. > So the union case is a non-issue here (it was only used to > make available enough properly aligned storage for the particular testcase). I agree that union case *should* be a non-issue in this context, where we were discussing how to fix placement new, but Gaby has made it one because he is claiming that placement new is not the only way to change the dynamic type of memory. Gaby's claim is that given an arbitrary pointer "p", saying: (int *)p = 3; is the same as saying: *(new (p) int) = 3; That makes life for the optimizers much, much harder. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29286