[PATCH] D96215: [clang-tidy] Recognize captures as a form of aliasing.

Artem Dergachev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 8 19:36:51 PST 2021


NoQ added a comment.

In D96215#2548492 <https://reviews.llvm.org/D96215#2548492>, @aaron.ballman wrote:

> Should structured bindings be treated similarly as well (not necessarily as part of this patch)?

Umm, looks like we're both missing the elephant in the room: passing a variable into a function by reference.

  int &hidden_reference(int &x) {
    return x;
  }
  
  void test_hidden_reference() {
    int x = 0;
    int &y = hidden_reference(x);
    for (; x < 10; ++y) { // Warns ¯\_(ツ)_/¯
    }
  }

With this taken care of, I hope structured bindings will be handled automatically because whatever's unwrapped couldn't have obtained a reference to our local variable without going through a function first (eg., the constructor). Unless there's some aggregate magic going on... but in this case, again, we have to take care of aggregate magic and structured bindings aren't at fault.


Repository:
  rCTE Clang Tools Extra

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96215/new/

https://reviews.llvm.org/D96215



More information about the cfe-commits mailing list