[PATCH] D96215: [clang-tidy] Aliasing: Add support for lambda captures.

Nathan James via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon May 3 23:06:56 PDT 2021


njames93 added a comment.

In D96215#2550227 <https://reviews.llvm.org/D96215#2550227>, @NoQ wrote:

> 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.

Just my $0.02, We shouldn't worry too much about pathological cases like that. I imagine that code would almost never appear in the wild. And for cases where you don't have access to definition for `hidden_reference `, there's not much that can be done anyway.


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

https://reviews.llvm.org/D96215



More information about the cfe-commits mailing list