public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* optimization/4641: Temporary is not destructed when -O is used with recursive fn.
@ 2001-10-21 23:46 b.bull
0 siblings, 0 replies; 2+ messages in thread
From: b.bull @ 2001-10-21 23:46 UTC (permalink / raw)
To: gcc-gnats
>Number: 4641
>Category: optimization
>Synopsis: Temporary is not destructed when -O is used with recursive fn.
>Confidential: no
>Severity: serious
>Priority: low
>Responsible: unassigned
>State: open
>Class: wrong-code
>Submitter-Id: net
>Arrival-Date: Sun Oct 21 23:46:00 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator: Brian Bull
>Release: gcc version 2.95.3 20010315 (release) [FreeBSD]
>Organization:
>Environment:
>Description:
Small example containing construction of a temporary as
a return value of a recursive function 'f'.
With -O, the temporary is never destructed.
Without -O, or if the code is rewritten to avoid
recursion, the temporary is destructed correctly.
Thanks in advance for looking at this.
>How-To-Repeat:
g++ example.C -o example
example
g++ example.C -o example -O
example
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/plain; name="example.C"
Content-Disposition: inline; filename="example.C"
#include <stream.h>
class A{
public:
double x;
~A(){cerr << "~A\n";}
A(double d){x = d; cerr << "A::A (double)\n";}
A(const A& a){x = a.x; cerr << "A::A (A)\n";}
};
A operator+(const A& a,double d){
return a.x+d;
}
double f(const A& a){
if (a.x==1){
return f(a+1); // the temporary created as the result of 'a+1' is never destructed if -O is used
// but without -O, or if we rewrite the program to avoid recursion,
// the destructor is called correctly
} else {
return a.x;
}
}
void main(){
A a(1);
f(a);
}
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: optimization/4641: Temporary is not destructed when -O is used with recursive fn.
@ 2002-04-03 0:55 rth
0 siblings, 0 replies; 2+ messages in thread
From: rth @ 2002-04-03 0:55 UTC (permalink / raw)
To: b.bull, gcc-bugs, gcc-prs, nobody
Synopsis: Temporary is not destructed when -O is used with recursive fn.
State-Changed-From-To: open->closed
State-Changed-By: rth
State-Changed-When: Wed Apr 3 00:55:07 2002
State-Changed-Why:
Probably fixed in gcc 3.0, though I didn't try it.
Definitely fixed in gcc 3.1.
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=4641
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2002-04-03 8:55 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-10-21 23:46 optimization/4641: Temporary is not destructed when -O is used with recursive fn b.bull
2002-04-03 0:55 rth
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).