From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19474 invoked by alias); 22 Apr 2002 09:06:02 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 19458 invoked by uid 71); 22 Apr 2002 09:06:01 -0000 Date: Mon, 22 Apr 2002 02:06:00 -0000 Message-ID: <20020422090601.19457.qmail@sources.redhat.com> To: nobody@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org, From: David Hanney Subject: Re: optimization/6330: tiny C++ prog broken under -O1 Reply-To: David Hanney X-SW-Source: 2002-04/txt/msg01103.txt.bz2 List-Id: The following reply was made to PR optimization/6330; it has been noted by GNATS. From: David Hanney To: rth@gcc.gnu.org, gcc-bugs@gcc.gnu.org, gcc-prs@gcc.gnu.org, nobody@gcc.gnu.org, gcc-gnats@gcc.gnu.org, gcc-bugs@gcc.gnu.org, gcc-prs@gcc.gnu.org, nobody@gcc.gnu.org Cc: Subject: Re: optimization/6330: tiny C++ prog broken under -O1 Date: Mon, 22 Apr 2002 10:02:00 +0100 Many thanks for your prompt response! I assumed (wrongly, I know) that because "the cast-output is the same four bytes as the cast-input" that it would be at the same address (union-style). My bad. But, given this behavior-set .. gcc with plain C++ works. (no compiler warning) gcc with optimized C++ doesn't work. (no compiler warning) gcc with C doesn't compile. (under gcc 2.95.4 and gcc 3) .. would a compiler warning be useful here? Especially as the pointer may be formed implicitly via a reference (as shown in the code quoted below) cheers, DH ------------------------------------------- #!/bin/sh # what compiler/OS version is it? gcc-3.0 -v uname -a # create a program echo '#include ' > x.cpp echo '#include ' >> x.cpp echo 'typedef unsigned char byte;' >> x.cpp; echo 'typedef byte *pbyte;' >> x.cpp; echo 'void change(pbyte &z) { z = (pbyte)"correct"; }' >> x.cpp echo 'int main() {' >> x.cpp echo ' char *s = "incorrect";' >> x.cpp echo ' change((byte*)s);' >> x.cpp echo ' printf("%s\n", s);' >> x.cpp echo ' exit(0);' >> x.cpp echo '}' >> x.cpp # compile and run it gcc-3.0 x.cpp ./a.out # compile and run The Same Program optimized gcc-3.0 -O1 x.cpp ./a.out ------------------------------------------- At 00:41 18/04/02 +0000, rth@gcc.gnu.org wrote: >Synopsis: tiny C++ prog broken under -O1 > >State-Changed-From-To: open->closed >State-Changed-By: rth >State-Changed-When: Wed Apr 17 17:41:35 2002 >State-Changed-Why: > Not a bug. You have taken the address of a temporary. > You wanted "change((byte**)&s)". > >http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=6330 >