Accidentally taking the size of a struct-pointer type or a value of this type is more common than explicitly using the & operator for the value. This patch extends the check to include these cases.
Details
- Reviewers
alexfh aaron.ballman lebedev.ri JonasToth - Commits
- rZORG1db596426f8e: [clang-tidy] Extend bugprone-sizeof-expression to check sizeof(pointers to…
rZORGeba65042c7ea: [clang-tidy] Extend bugprone-sizeof-expression to check sizeof(pointers to…
rG1db596426f8e: [clang-tidy] Extend bugprone-sizeof-expression to check sizeof(pointers to…
rGeba65042c7ea: [clang-tidy] Extend bugprone-sizeof-expression to check sizeof(pointers to…
rCTE360114: [clang-tidy] Extend bugprone-sizeof-expression to check sizeof(pointers to…
rGecd1a82ee208: [clang-tidy] Extend bugprone-sizeof-expression to check sizeof(pointers to…
rL360114: [clang-tidy] Extend bugprone-sizeof-expression to check sizeof(pointers to…
Diff Detail
- Repository
- rL LLVM
Event Timeline
test/clang-tidy/bugprone-sizeof-expression.cpp | ||
---|---|---|
196 ↗ | (On Diff #197101) | While I trust Clang and the matchers to unroll the type and still match, I'd prefer also adding a test case for typedef TMyStruct* PMyStruct2; or somesuch. And perhaps a "copy" of these cases where they come from template arguments, in case the checker can also warn for that? |
231 ↗ | (On Diff #197101) | Why is this printed at sizeof(A*)? Do we not print the name of the actual type used in the expression? |
Aside from the testing request, this LGTM.
test/clang-tidy/bugprone-sizeof-expression.cpp | ||
---|---|---|
231 ↗ | (On Diff #197101) | The original check did this, so it's not really new behavior here. I don't recall the rationale off the top of my head, but I'd guess it's because the type is not really salient, but the fact that the type is a pointer is. |
test/clang-tidy/bugprone-sizeof-expression.cpp | ||
---|---|---|
196 ↗ | (On Diff #197101) | I added the new test, but templates are outside the scope of this particular patch. They should be tested (and fixed if the tests fail) in another patch. |