This is an archive of the discontinued LLVM Phabricator instance.

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

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

Event Timeline

arphaman updated this revision to Diff 72913.Sep 28 2016, 3:47 PM
arphaman retitled this revision from to Fix PR 10758: Infinite recursion when dealing with copy-initialization.
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.Apr 21 2017, 4:07 AM
arphaman added reviewers: ahatanak, v.g.vassilev.

Rebased the patch.

v.g.vassilev edited edge metadata.Apr 30 2017, 4:30 AM

I am not very familiar with this code here. This seems a reasonable fix to me. Unless @rsmith and @ahatanak have objections, please go ahead and land it some time next week.

cynecx added a subscriber: cynecx.May 8 2017, 10:03 AM

Would it be possible to land this patch? I would really like to see this fixed.

Gentle ping.

I will commit it today.

This revision was automatically updated to reflect the committed changes.