This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Bug with Named Return Values in C++
- From: Johny Cage <cage at ok dot ru>
- To: bug-gcc at gnu dot org
- Date: Mon, 22 Jul 2002 01:33:32 +0400
- Subject: Bug with Named Return Values in C++
- Organization: JohnSoft
- Reply-to: Johny Cage <cage at ok dot ru>
Hello bug-gcc,
I write code that uses named return values
(http://gcc.gnu.org/onlinedocs/gcc-2.95.3/gcc_5.html)
Code:
#include "stdio.h"
class T
{
const char *s;
int len;
public:
inline T(const char *str,int l):s(str),len(l) {}
inline const char *GetStr() {return s;}
};
T f();
int main()
{
printf("%s\n",f().GetStr());
}
T f() return s("zxc",3);
{
return s;
}
Compile it with
g++ -O6 -Wall -o bug bug.cpp
It should produce output "zxc", but it doesn't.
When I compile it with
g++ -O6 -Wall -S bug.cpp
I see, the function f returns object in stack, but main() waits it in
eax:edx pair. If function f rewrite as follows
T f()// return s("zxc",3);
{
T s("zxc",3);
return s;
}
All became Ok.
[~]$ gcc -v
Using builtin specs.
gcc version 2.95.2 19991024 (release)
And
G:\>gcc -v
Reading specs from /cygdrive/c/h/cygwin/bin/../lib/gcc-lib/i686-pc-cygwin/2.95.3-5/specs
gcc version 2.95.3-5 (cygwin special)
--
Best regards,
Johny mailto:cage@ok.ru