This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/34824] [4.1/4.2/4.3 Regression] ICE with explicit copy constructor
- From: "jakub at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 21 Jan 2008 20:29:32 -0000
- Subject: [Bug c++/34824] [4.1/4.2/4.3 Regression] ICE with explicit copy constructor
- References: <bug-34824-15653@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #4 from jakub at gcc dot gnu dot org 2008-01-21 20:29 -------
Related testcase:
struct A;
struct B
{
B (A const &);
B (B &);
};
struct A
{
A (B) {}
};
B
f (A const &a)
{
return B (a);
}
which doesn't have explicit at all segfaults as well, also endless recursion.
In both cases the copy constructor can't be used,
so a conversion through A(B) constructor and then B(const A&) is attempted.
But that needs a temporary, so a B(const B &) copy constructor is needed and
we are back to the original problem.
If A's constructor is instead A (const B &) {}, then it compiles just fine
in both variants ( explicit B (const B &); and B (B &); ). So I guess we just
need to detect recursion here. I believe C++ will try only one hop through
some
other class' constructor, so perhaps just remembering one parent type would
be enough to prevent the recursion.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34824