From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31892 invoked by alias); 18 May 2010 15:01:01 -0000 Received: (qmail 31828 invoked by uid 48); 18 May 2010 15:00:49 -0000 Date: Tue, 18 May 2010 15:01:00 -0000 Message-ID: <20100518150049.31827.qmail@sourceware.org> X-Bugzilla-Reason: CC References: Subject: [Bug middle-end/44164] [4.5 Regression] Aliasing bug triggered by Boost.Bind/Boost.Function In-Reply-To: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "rguenth at gcc dot gnu dot org" 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: 2010-05/txt/msg01926.txt.bz2 ------- Comment #11 from rguenth at gcc dot gnu dot org 2010-05-18 15:00 ------- (In reply to comment #10) > (In reply to comment #9) > > But the standard says in [basic.types] that "For any trivially copyable type T, > > if two pointers to T point to distinct T objects obj1 and obj2, where neither > > obj1 nor obj2 is a base-class subobject, if the underlying bytes (1.7) making > > up obj1 are copied into obj2,40 obj2 shall subsequently hold the same value as > > obj1." > > Yep. But an assignment is not a byte-copy and exactly the assignment is > what invokes the undefined behavior (not the subsequent access). > > So, > > struct X > { > char data[ sizeof( float ) ]; > }; > > int main() > { > X x1; > new( &x1.data ) float( 3.14f ); > > X x2 = x1; > > > GCC sees this as reading the float object you made live in x1.data via > an lvalue of type X and thus decides that the float object is unused > and removes it. Oh, and "float" is a trivially copyable type. Copying X results in copying the bytes of X::data (because the default copy constructor of a class does a memberwise copy, and the default copy constructor of an array does an elementwise copy). Therefore, the underlying bytes of the object of type float, initialized at x1.data, are copied into x2.data, which then must, if interpreted as a float, hold the same value as the original object. is not what the C++ frontend does. It emits the assignment literally: <) >>> >>; gimplified to x2 = x1; -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44164