Fix PR 10758: Infinite recursion when dealing with copy-initialization
Needs ReviewPublic

Authored by arphaman on Sep 28 2016, 3:47 PM.

Details

Summary

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&);
  ^

Diff Detail

Repository
rL LLVM
arphaman retitled this revision from to Fix PR 10758: Infinite recursion when dealing with copy-initialization.Sep 28 2016, 3:47 PM
arphaman updated this object.
arphaman added a reviewer: rsmith.
arphaman set the repository for this revision to rL LLVM.
arphaman added a subscriber: cfe-commits.
arphaman updated this revision to Diff 96122.Fri, Apr 21, 4:07 AM
arphaman added reviewers: ahatanak, v.g.vassilev.

Rebased the patch.