Article View: gnu.g++.bug
Article #1759G++ 1.34.1 named return values (no fix)
From: rjc
Date: Fri, 17 Mar 1989 21:50
Date: Fri, 17 Mar 1989 21:50
94 lines
2435 bytes
2435 bytes
rjc@cs.ucla.edu
Vax 8350, Ultrix 2.2-1 System #4
G++ 1.34.1 (plus patched cplus-decl.c) Gcc 1.34
>[ Patch from Michael for cplus-decl.c ... ]
>
>yahi%
>================================================================
>Here is the test program which now compiles:
>
>struct A {
> int i;
> A(int x) { printf("A(%d)\n", x); i = x; };
> A(A& x) { printf("A(A& x), x.i == %d\n", x.i); i = x.i; };
> ~A(void) { printf("~A(%d)\n", i); };
> void operator += (A& x) { printf("+=(%d, %d)\n", i, x.i); i += x.i; };
>};
>
>A foo (void) return tmp = 4;
>{
> printf("foo(void), tmp.i == %d\n", tmp.i);
> return tmp;
>}
>
>main()
>{
> A bar = 5;
> bar += foo();
> printf("main(), bar.i == %d\n", bar.i);
>}
>================================================================
>And here are the results:
>
>yahi% a.out
>A(5)
>A(4) <- ******** ~A() never called
>foo(void), tmp.i == 4
>A(A& x), x.i == 4 <- ******** Shouldn't be called
>+=(5, 4)
>~A(4)
>main(), bar.i == 9
>~A(9)
>yahi%
>================================================================
>
>Michael
Michael,
Yes, the patch allows the test program to compile. Unfortunately, the
code that is produced is badly broken. You can see in the above output
that A(A&) is called on return from foo(). This is not supposed to
happen with a named return (as I understand it). This is not too bad,
just the same old inefficiency that we have been suffering with up to
now. The *big* problem is that ~A() is not called for the `tmp' in foo(),
but only for the copy produced by the call to A(A&) on return from foo().
I an not familiar with the interals of g++, so I cannot provide a fix.
Thanks,
rob collins
(rjc@cs.ucla.edu)
i
n
e
w
s
i
s
b
r
a
i
n
d
a
m
a
g
e
d
-------------------------------------------------------------------------------
rjc@cs.ucla.edu
This is what happens when I sit on my keyboard: AISBDFAORI:KHGEDSYTFBFISKVDJ MN
Next week: what happens when I throw my keyboard out the window!
Technical Details
Message-ID:
<21944@shemp.CS.UCLA.EDU>Path:
arc1-ca.pugleaf.net!utzoo!telly!attcan!uunet!bu-cs!bloom-beacon!oberon!ucla-cs!rjcShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!telly!attcan!uunet!bu-cs!bloom-beacon!oberon!ucla-cs!rjc From: rjc@maui.cs.ucla.edu Newsgroups: gnu.g++.bug Subject: G++ 1.34.1 named return values (no fix) Message-ID: <21944@shemp.CS.UCLA.EDU> Date: 17 Mar 89 21:50:55 GMT Sender: news@CS.UCLA.EDU Reply-To: rjc@CS.UCLA.EDU () Distribution: gnu Organization: UCLA Computer Science Department Lines: 94