public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Copy constructor with non const rhs arg
@ 2004-05-12 15:06 paul moore
  2004-05-12 16:05 ` Eljay Love-Jensen
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: paul moore @ 2004-05-12 15:06 UTC (permalink / raw)
  To: gcc-help

This code does not compile on gcc (3.2.2 on rh9 - 3.3 on suse 9)
 
class test
{
public:
int x;
test(test &rhs)
{
	x = rhx.x;
}
};

test foo();
int main(int argc, char* argv[])
{
	test dd = foo();
	return 0;
}

The test dd line gets hit saying there is no match for test::test(test), the
candidates are test::test(test&)
If I change the copy constructor to 'test(const test&)' it compiles fine.

What am I trying to do? In real life the class contains an auto_ptr - since
the auto_ptr copy constructor updates the rhs you cannot pass it in with
const. (Note the auto_ptr copy constructor itself is declared with a non
const rhs - and code using it compiles fine - this is really puzzling)

Also if I change foo to 'test &foo()' it compiles fine (but of course this
is totally different semantics)
Note also that MSFT vs 2003 compiles this code quite happily.


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2004-05-12 18:43 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-05-12 15:06 Copy constructor with non const rhs arg paul moore
2004-05-12 16:05 ` Eljay Love-Jensen
2004-05-12 16:15   ` Eljay Love-Jensen
2004-05-12 16:43   ` Tony Wetmore
2004-05-12 16:26 ` Eljay Love-Jensen
2004-05-12 18:08 ` llewelly
2004-05-12 18:43   ` paul moore

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).