[PATCH] D156189: [-Wunsafe-buffer-usage] Refactor to let local variable fix-its and parameter fix-its share common code
Ziqing Luo via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 24 17:32:05 PDT 2023
ziqingluo-90 added inline comments.
================
Comment at: clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-local-var-span.cpp:242
ptr[2] = 30;
- auto p = new int[10];
- // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:11}:"std::span<int> p"
----------------
We no longer generate fix-its for a variable declaration where the type specifier is just `auto`. This is to avoid that fix-its may become incorrect when the adopting codebase changes. For example,
```
int x;
auto p = &x;
```
If we fix the declaration of `p` to `std::span<int> p{&x, 1}`, and later `int x` is changed to `long x`, the program becomes incorrect and the programmer may not know that the type of `p` should simply follow the type of `x`.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D156189/new/
https://reviews.llvm.org/D156189
More information about the cfe-commits
mailing list