After passing a pointer by reference, the pointer is not updated properly. A pointer is initialized to 0. It is then passed by reference to another function, where it is updated to 1. After returning to the calling function, the pointer appears to be 0. Looking at the assembly code, it appears as if the initialized value 0 is propagated accross the function call. Because of this, the conditional is always true, and the debug message always prints. This only occurs with optimizations on (O1--O5). Without optimizations, the code is correct. Release: gcc version 2.95.3 20010315 (Debian release) Environment: gnu/linux, debian distribution, kernel 2.2.15 Pentium III How-To-Repeat: g++ -Wall -O3 -o voidbug voidbug.cpp Source code is attached. Makefile is included.
Fix: I defined the pointer as a void* initially, and then removed the typecast on the function argument. The code then appears to work properly.
From: "Billinghurst, David (CRTS)" <David.Billinghurst@riotinto.com> To: "'gcc-gnats@gcc.gnu.org'" <gcc-gnats@gcc.gnu.org>, "'hankinsr@umich.edu'" <hankinsr@umich.edu>, nobody@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org, gcc-bugs@gcc.gnu.org Subject: RE: c++/2350: constant propagation problem accross function call Date: Fri, 23 Mar 2001 01:44:44 -0000 This looks very similar to PR fortran/1645, http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view&pr=1645&database=gcc That test case no longer fails for me on cygwin, but still fails on i686-pc-linux-gnu
State-Changed-From-To: open->analyzed State-Changed-Why: Not a bug. The cast converts your lvalue to an rvalue, which leads you referencing a temporary rather than the variable that you intended. It would be Really Nice if -Wall would diagnose this, so I'm leaving the PR open, and re-categorizing it.
From: =?iso-8859-1?q?Puneet=20Singh?= <puneet762k1@yahoo.co.in> To: rth@gcc.gnu.org, gcc-bugs@gcc.gnu.org, gcc-prs@gcc.gnu.org, hankinsr@umich.edu, nobody@gcc.gnu.org, gcc-gnats@gcc.gnu.org Cc: Subject: Re: c++/2350: No warning for referencing a temporary Date: Tue, 2 Apr 2002 09:46:33 +0100 (BST) Hi How to unsubscribe from the list greetings Puneet --- rth@gcc.gnu.org wrote: > Old Synopsis: constant propagation problem accross > function call > New Synopsis: No warning for referencing a temporary > > State-Changed-From-To: open->analyzed > State-Changed-By: rth > State-Changed-When: Mon Apr 1 23:58:06 2002 > State-Changed-Why: > Not a bug. The cast converts your lvalue to an > rvalue, which > leads you referencing a temporary rather than > the variable > that you intended. > > It would be Really Nice if -Wall would diagnose > this, so I'm > leaving the PR open, and re-categorizing it. > > http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=2350 ________________________________________________________________________ For live cricket scores download Yahoo! Score Tracker at: http://in.sports.yahoo.com/cricket/tracker.html
*** This bug has been marked as a duplicate of 1920 ***
confirmed dupe.