Bug 2350 - No warning for referencing a temporary
Summary: No warning for referencing a temporary
Status: CLOSED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 2.95.3
: P3 enhancement
Target Milestone: ---
Assignee: Wolfgang Bangerth
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2001-03-22 17:36 UTC by hankinsr
Modified: 2005-07-23 22:46 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2003-01-01 00:00:00


Attachments
voidbug.tar.bz2 (7.38 KB, application/octet-stream)
2003-05-21 15:16 UTC, hankinsr
Details

Note You need to log in before you can comment on or make changes to this bug.
Description hankinsr 2001-03-22 17:36:00 UTC
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.
Comment 1 hankinsr 2001-03-22 17:36:00 UTC
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.
Comment 2 david.billinghurst 2001-03-23 01:44:44 UTC
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 
Comment 3 Richard Henderson 2002-04-01 23:58:06 UTC
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.
Comment 4 puneet762k1 2002-04-02 09:46:33 UTC
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
Comment 5 Wolfgang Bangerth 2003-05-06 01:05:24 UTC
*** This bug has been marked as a duplicate of 1920 ***
Comment 6 Nathanael C. Nerode 2003-05-23 06:02:54 UTC
confirmed dupe.