aaron.ballman added a comment.

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

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

Additionally, pointers to non-const objects. I had assumed both of these were 
intentionally out-of-scope because of flow sensitivity though.

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

FWIW, I was thinking of code like: https://godbolt.org/z/jK53G5 but, I don't 
think it needs to be handled right now in this patch.


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D96215

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to