Xazax-hun wrote:

Note that &array[idx] is perfectly valid code when `idx == number of elements`. 
And it is relatively common to do that when one is using STL algorithms on 
arrays:
```
auto it = std::find(&array[0], &array[size], foo);
```

Of course, one could use the `begin/end` free functions, but those are only 
available since C++11. 

Could you elaborate on alternative approaches you considered fixing the problem 
and why you chose this one? E.g., would trying to look at the parent regions 
for expressions like `foo[idx].bar` work? Or is the source of the problem that 
you'd also need the exact expression for the subscript instead of the 
`MemberExpr`?

Alternatively, would it be possible to suppress warnings on the common pattern 
`&array[idx]` by checking the parent of the subscript expression in the AST 
(but still emitting a warning when the pointer is dereferenced)?


https://github.com/llvm/llvm-project/pull/72107
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to