[Bug c++/16982] New: wrong copy ctor called
boris at kolpackov dot net
gcc-bugzilla@gcc.gnu.org
Wed Aug 11 15:42:00 GMT 2004
$ cat >test.cxx
extern "C" void
abort ();
struct base
{
base ()
{
}
base (base const&)
{
abort ();
}
};
struct derived : base
{
derived ()
{
}
derived (derived const&)
: base ()
{
}
};
struct s
{
operator derived ()
{
return derived ();
}
};
int
main ()
{
s s;
base const& b (s);
}
$ g++-3.4 --version
g++-3.4 (GCC) 3.4.1 (Debian 3.4.1-5)
$ g++-3.4 test.cxx
$ ./a.out
Aborted
$ g++-3.3 --version
g++-3.3 (GCC) 3.3.4 (Debian 1:3.3.4-7)
$ g++-3.3 test.cxx
$ ./a.out
Aborted
Here is a quote from 8.5.3/5 bullet 2, sub-bullet 1, sub-sub-bullet 2:
A temporary of type cv1 T2 [sic] is created, and a constructor is called to
copy the entire rvalue object into the temporary. The reference is bound to the
temporary or to a subobject within the temporary.
The constructor that would be used to make the copy shall be callable whether
or not the copy is actually done.
[Example:
struct A { };
struct B : public A { } b;
extern B f();
const A& rca = f(); // Either bound to the A subobject of the B rvalue,
// or the entire B object is copied and the reference
// is bound to the A subobject of the copy
--end example]
--
Summary: wrong copy ctor called
Product: gcc
Version: 3.4.1
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: boris at kolpackov dot net
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: i686-pc-linux-gnu
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16982
More information about the Gcc-bugs
mailing list