Article View: gnu.g++.bug
Article #1752help with named return values
From: Michael Tiemann
Date: Fri, 17 Mar 1989 06:27
Date: Fri, 17 Mar 1989 06:27
75 lines
2648 bytes
2648 bytes
yahi% diff -c2 cplus-decl.c~ cplus-decl.c
*** cplus-decl.c~ Wed Mar 15 09:26:48 1989
--- cplus-decl.c Thu Mar 16 22:23:57 1989
***************
*** 2999,3003 ****
If not, it will get done when the type is completed. */
! if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL)
{
int toplev = current_binding_level == global_binding_level;
--- 2999,3004 ----
If not, it will get done when the type is completed. */
! if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL
! || TREE_CODE (decl) == RESULT_DECL)
{
int toplev = current_binding_level == global_binding_level;
***************
*** 6776,6781 ****
/* If we have a named return value, put that in our scope as well. */
if (DECL_NAME (DECL_RESULT (current_function_decl)) != value_identifier)
! finish_decl (DECL_RESULT (current_function_decl),
! DECL_INITIAL (DECL_RESULT (current_function_decl)), 0);
}
--- 6777,6785 ----
/* If we have a named return value, put that in our scope as well. */
if (DECL_NAME (DECL_RESULT (current_function_decl)) != value_identifier)
! {
! pushdecl (DECL_RESULT (current_function_decl));
! finish_decl (DECL_RESULT (current_function_decl),
! DECL_INITIAL (DECL_RESULT (current_function_decl)), 0);
! }
}
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)
foo(void), tmp.i == 4
A(A& x), x.i == 4
+=(5, 4)
~A(4)
main(), bar.i == 9
~A(9)
yahi%
================================================================
Michael
Technical Details
Message-ID:
<8903170627.AA19172@yahi>Path:
arc1-ca.pugleaf.net!utzoo!telly!attcan!dptcdc!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!YAHI.STANFORD.EDU!mdtShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!telly!attcan!dptcdc!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!YAHI.STANFORD.EDU!mdt From: mdt@YAHI.STANFORD.EDU (Michael Tiemann) Newsgroups: gnu.g++.bug Subject: help with named return values Message-ID: <8903170627.AA19172@yahi> Date: 17 Mar 89 06:27:42 GMT Sender: daemon@tut.cis.ohio-state.edu Reply-To: tiemann@lurch.stanford.edu Distribution: gnu Organization: GNUs Not Usenet Lines: 75