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