[PATCH] D141058: [clang-tidy] fix wrong fixup for bugprone-implicit-widening-of-multiplication-result
Vincent LE GARREC via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jan 9 01:49:32 PST 2023
bansan added a comment.
Herald added a subscriber: StephenFan.
I just made a test:
#include <cstdint>
#include <vector>
int64_t f(int x) {
return 1024 * 1024 * 1024 * x;
}
void g(int x) {
std::vector<int> b;
b.reserve(1024 * 1024 * 1024 * x);
}
int main() {
f(1024);
g(1024);
}
The fixed code:
#include <cstddef>
#include <cstdint>
#include <vector>
int64_t f(int x) {
return static_cast<int64_t>(1024 * 1024 * 1024 * x);
}
void g(int x) {
std::vector<int> b;
b.reserve(static_cast<size_type>(1024 * 1024 * 1024 * x));
}
int main() {
f(1024);
g(1024);
}
For the first test, I still think that the auto fix should be `return static_cast<int64_t>(1024) * 1024 * 1024 * x;` to have the good result.
For the second test, the type is the internal type of `std::vector`.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D141058/new/
https://reviews.llvm.org/D141058
More information about the cfe-commits
mailing list