HomePhabricator

Fix the second half of PR34266: Don't implicitly capture '*this' if the…

Description

Fix the second half of PR34266: Don't implicitly capture '*this' if the members are found in a class unrelated to the enclosing class.

https://bugs.llvm.org/show_bug.cgi?id=34266

For e.g.

struct A {
   void f(int);
   static void f(char);
};
struct B {
  auto foo() {
    return [&] (auto a) {
       A::f(a); // this should not cause a capture of '*this'
    };
  }
};

The patch does the following:

  1. It moves the check to attempt an implicit capture of '*this' by reference into the more logical location of when the call is actually built within ActOnCallExpr (as opposed to when the unresolved-member-lookup node is created).
    • Reminder: A capture of '*this' by value has to always be an explicit capture.
  1. It additionally checks whether the naming class of the UnresolvedMemberExpr ('A' in the example above) is related to the enclosing class ('B' above).

P.S. If you have access to ISO-C++'s CWG reflector, see this thread for some potentially related discussion: http://lists.isocpp.org/core/2017/08/2851.php

Details

Committed
faisalvSep 17 2017, 8:37 AM
Parents
rL313486: [RISCV] Add support for disassembly
Branches
Unknown
Tags
Unknown