Topic: Question on requirement for copy constructor availability
Author: "Greg Herlihy" <greghe@pacbell.net>
Date: Mon, 12 Feb 2007 17:03:43 CST Raw View
On Feb 9, 12:30 pm, "Fadi Beyrouti" <fbeyr...@gmail.com> wrote:
> Sorry I have no copy of the standard but I'll try to describe the
> problem as clearly as I can:
>
> --------------------------------------------------------------------------
> struct D : private noncopyable {};
>
> void foo(const D &);
>
> foo (D()); // LINE A: THIS SHOULD NOT COMPILE according to the
> standard.
> D inst; foo (inst); // LINE B: THIS IS OK
> --------------------------------------------------------------------------
>
> My question is why is the standard permitting a copy in the first case
> but not in the second? What is the fundamental difference between the
> two cases?
In the first call to foo() the argument is an rvalue, in the second
call it is an lvalue.
> According to the discussions inhttp://gcc.gnu.org/bugzilla/show_bug.cgi?id=14618http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14528http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14774
> gcc 3.4 and later seems to be the only compiler enforcing this rule
> (at least at the time the bugs were posted.)
Under the current Standard, whether or not a copy needs to be made in
this situation is implementation-defined. In the current draft of the
Standard, this choice has been eliminated: the compiler may no longer
copy the temporary in the first case - so no copy constructor for the
argument type needs to be accessible. Therefore according to the
current draft, both calls are well-formed.
Greg
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: "Fadi Beyrouti" <fbeyrout@gmail.com>
Date: Fri, 9 Feb 2007 14:30:56 CST Raw View
Sorry I have no copy of the standard but I'll try to describe the
problem as clearly as I can:
--------------------------------------------------------------------------
struct D : private noncopyable {};
void foo(const D &);
foo (D()); // LINE A: THIS SHOULD NOT COMPILE according to the
standard.
D inst; foo (inst); // LINE B: THIS IS OK
--------------------------------------------------------------------------
My question is why is the standard permitting a copy in the first case
but not in the second? What is the fundamental difference between the
two cases?
According to the discussions in
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14618
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14528
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14774
gcc 3.4 and later seems to be the only compiler enforcing this rule
(at least at the time the bugs were posted.)
--
Fadi Beyrouti
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]