This patch fixes a bug that's tracked by PR 10758 and duplicates like PR 30343.
The bug causes clang to crash with a stack overflow while recursing infinitely trying to perform copy-initialization on a type without a copy constructor but with a constructor that accepts another type that can be constructed using the original type. This example shows the structures and code that causes this behavior:
struct Bar; struct Foo { Foo(Bar); }; struct Bar { Bar(const Foo&); Bar(Bar&); }; Foo foo(const Bar &b) { return b; }
The patch fixes this bug by detecting the recursive behavior and failing correctly with an appropriate error message. It also tries to provide a meaningful diagnostic note about the constructor which leads to this behavior, like in the example shown below:
foo.cpp:6:3: note: candidate constructor not viable: no known conversion from 'const Bar' to 'const Foo &' for 1st argument Bar(const Foo&); ^