[clang-tidy] autofix cppcoreguidelines (#1932)

* [clang-tidy] autofix cppcoreguidelines

* better than automation maybe
This commit is contained in:
dominic 2025-02-12 11:32:45 -08:00 committed by GitHub
parent f8db7f6c07
commit 2d4c8dd21a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 28 additions and 28 deletions

View File

@ -1692,7 +1692,7 @@ class BENCHMARK_EXPORT BenchmarkReporter {
CPUInfo const& cpu_info; CPUInfo const& cpu_info;
SystemInfo const& sys_info; SystemInfo const& sys_info;
// The number of chars in the longest benchmark name. // The number of chars in the longest benchmark name.
size_t name_field_width; size_t name_field_width = 0;
static const char* executable_name; static const char* executable_name;
Context(); Context();
}; };

View File

@ -186,7 +186,7 @@ IterationCount ComputeIters(const benchmark::internal::BenchmarkInstance& b,
} // end namespace } // end namespace
BenchTimeType ParseBenchMinTime(const std::string& value) { BenchTimeType ParseBenchMinTime(const std::string& value) {
BenchTimeType ret; BenchTimeType ret = {};
if (value.empty()) { if (value.empty()) {
ret.tag = BenchTimeType::TIME; ret.tag = BenchTimeType::TIME;
@ -195,7 +195,7 @@ BenchTimeType ParseBenchMinTime(const std::string& value) {
} }
if (value.back() == 'x') { if (value.back() == 'x') {
char* p_end; char* p_end = nullptr;
// Reset errno before it's changed by strtol. // Reset errno before it's changed by strtol.
errno = 0; errno = 0;
IterationCount num_iters = std::strtol(value.c_str(), &p_end, 10); IterationCount num_iters = std::strtol(value.c_str(), &p_end, 10);
@ -217,7 +217,7 @@ BenchTimeType ParseBenchMinTime(const std::string& value) {
"Eg., `30s` for 30-seconds."; "Eg., `30s` for 30-seconds.";
} }
char* p_end; char* p_end = nullptr;
// Reset errno before it's changed by strtod. // Reset errno before it's changed by strtod.
errno = 0; errno = 0;
double min_time = std::strtod(value.c_str(), &p_end); double min_time = std::strtod(value.c_str(), &p_end);

View File

@ -38,7 +38,7 @@ struct RunResults {
}; };
struct BENCHMARK_EXPORT BenchTimeType { struct BENCHMARK_EXPORT BenchTimeType {
enum { ITERS, TIME } tag; enum { UNSPECIFIED, ITERS, TIME } tag;
union { union {
IterationCount iters; IterationCount iters;
double time; double time;

View File

@ -105,7 +105,7 @@ std::string ExponentToPrefix(int64_t exponent, bool iec) {
std::string ToBinaryStringFullySpecified(double value, int precision, std::string ToBinaryStringFullySpecified(double value, int precision,
Counter::OneK one_k) { Counter::OneK one_k) {
std::string mantissa; std::string mantissa;
int64_t exponent; int64_t exponent = 0;
ToExponentAndMantissa(value, precision, ToExponentAndMantissa(value, precision,
one_k == Counter::kIs1024 ? 1024.0 : 1000.0, &mantissa, one_k == Counter::kIs1024 ? 1024.0 : 1000.0, &mantissa,
&exponent); &exponent);
@ -119,7 +119,7 @@ std::string StrFormatImp(const char* msg, va_list args) {
// TODO(ericwf): use std::array for first attempt to avoid one memory // TODO(ericwf): use std::array for first attempt to avoid one memory
// allocation guess what the size might be // allocation guess what the size might be
std::array<char, 256> local_buff; std::array<char, 256> local_buff = {};
// 2015-10-08: vsnprintf is used instead of snd::vsnprintf due to a limitation // 2015-10-08: vsnprintf is used instead of snd::vsnprintf due to a limitation
// in the android-ndk // in the android-ndk

View File

@ -252,7 +252,7 @@ int CountSetBitsInCPUMap(std::string val) {
CPUMask mask(benchmark::stoul(part, nullptr, 16)); CPUMask mask(benchmark::stoul(part, nullptr, 16));
return static_cast<int>(mask.count()); return static_cast<int>(mask.count());
}; };
std::size_t pos; std::size_t pos = 0;
int total = 0; int total = 0;
while ((pos = val.find(',')) != std::string::npos) { while ((pos = val.find(',')) != std::string::npos) {
total += CountBits(val.substr(0, pos)); total += CountBits(val.substr(0, pos));
@ -587,7 +587,7 @@ class ThreadAffinityGuard final {
private: private:
bool SetAffinity() { bool SetAffinity() {
#if defined(BENCHMARK_HAS_PTHREAD_AFFINITY) #if defined(BENCHMARK_HAS_PTHREAD_AFFINITY)
int ret; int ret = 0;
self = pthread_self(); self = pthread_self();
ret = pthread_getaffinity_np(self, sizeof(previous_affinity), ret = pthread_getaffinity_np(self, sizeof(previous_affinity),
&previous_affinity); &previous_affinity);
@ -627,8 +627,8 @@ class ThreadAffinityGuard final {
} }
#if defined(BENCHMARK_HAS_PTHREAD_AFFINITY) #if defined(BENCHMARK_HAS_PTHREAD_AFFINITY)
pthread_t self; pthread_t self{};
cpu_set_t previous_affinity; cpu_set_t previous_affinity{};
#elif defined(BENCHMARK_OS_WINDOWS_WIN32) #elif defined(BENCHMARK_OS_WINDOWS_WIN32)
HANDLE self; HANDLE self;
DWORD_PTR previous_affinity; DWORD_PTR previous_affinity;
@ -642,7 +642,7 @@ double GetCPUCyclesPerSecond(CPUInfo::Scaling scaling) {
(void)scaling; (void)scaling;
#if defined BENCHMARK_OS_LINUX || defined BENCHMARK_OS_CYGWIN #if defined BENCHMARK_OS_LINUX || defined BENCHMARK_OS_CYGWIN
long freq; long freq = 0;
// If the kernel is exporting the tsc frequency use that. There are issues // If the kernel is exporting the tsc frequency use that. There are issues
// where cpuinfo_max_freq cannot be relied on because the BIOS may be // where cpuinfo_max_freq cannot be relied on because the BIOS may be

View File

@ -143,7 +143,7 @@ double ProcessCPUUsage() {
#elif defined(CLOCK_PROCESS_CPUTIME_ID) && !defined(BENCHMARK_OS_MACOSX) #elif defined(CLOCK_PROCESS_CPUTIME_ID) && !defined(BENCHMARK_OS_MACOSX)
// FIXME We want to use clock_gettime, but its not available in MacOS 10.11. // FIXME We want to use clock_gettime, but its not available in MacOS 10.11.
// See https://github.com/google/benchmark/pull/292 // See https://github.com/google/benchmark/pull/292
struct timespec spec; struct timespec spec {};
if (clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &spec) == 0) { if (clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &spec) == 0) {
return MakeTime(spec); return MakeTime(spec);
} }
@ -200,7 +200,7 @@ double ThreadCPUUsage() {
if (getrusage(RUSAGE_LWP, &ru) == 0) return MakeTime(ru); if (getrusage(RUSAGE_LWP, &ru) == 0) return MakeTime(ru);
DiagnoseAndExit("getrusage(RUSAGE_LWP, ...) failed"); DiagnoseAndExit("getrusage(RUSAGE_LWP, ...) failed");
#elif defined(CLOCK_THREAD_CPUTIME_ID) #elif defined(CLOCK_THREAD_CPUTIME_ID)
struct timespec ts; struct timespec ts {};
if (clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts) == 0) { if (clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts) == 0) {
return MakeTime(ts); return MakeTime(ts);
} }
@ -217,9 +217,9 @@ std::string LocalDateTimeString() {
const std::size_t kTzOffsetLen = 6; const std::size_t kTzOffsetLen = 6;
const std::size_t kTimestampLen = 19; const std::size_t kTimestampLen = 19;
std::size_t tz_len; std::size_t tz_len = 0;
std::size_t timestamp_len; std::size_t timestamp_len = 0;
long int offset_minutes; long int offset_minutes = 0;
char tz_offset_sign = '+'; char tz_offset_sign = '+';
// tz_offset is set in one of three ways: // tz_offset is set in one of three ways:
// * strftime with %z - This either returns empty or the ISO 8601 time. The // * strftime with %z - This either returns empty or the ISO 8601 time. The
@ -239,7 +239,7 @@ std::string LocalDateTimeString() {
#if defined(BENCHMARK_OS_WINDOWS) #if defined(BENCHMARK_OS_WINDOWS)
std::tm* timeinfo_p = ::localtime(&now); std::tm* timeinfo_p = ::localtime(&now);
#else #else
std::tm timeinfo; std::tm timeinfo{};
std::tm* timeinfo_p = &timeinfo; std::tm* timeinfo_p = &timeinfo;
::localtime_r(&now, &timeinfo); ::localtime_r(&now, &timeinfo);
#endif #endif

View File

@ -13,11 +13,11 @@ namespace {
class TestReporter : public benchmark::ConsoleReporter { class TestReporter : public benchmark::ConsoleReporter {
public: public:
virtual bool ReportContext(const Context& context) override { bool ReportContext(const Context& context) override {
return ConsoleReporter::ReportContext(context); return ConsoleReporter::ReportContext(context);
}; };
virtual void ReportRuns(const std::vector<Run>& report) override { void ReportRuns(const std::vector<Run>& report) override {
assert(report.size() == 1); assert(report.size() == 1);
iter_nums_.push_back(report[0].iterations); iter_nums_.push_back(report[0].iterations);
ConsoleReporter::ReportRuns(report); ConsoleReporter::ReportRuns(report);
@ -25,7 +25,7 @@ class TestReporter : public benchmark::ConsoleReporter {
TestReporter() {} TestReporter() {}
virtual ~TestReporter() {} ~TestReporter() override {}
const std::vector<benchmark::IterationCount>& GetIters() const { const std::vector<benchmark::IterationCount>& GetIters() const {
return iter_nums_; return iter_nums_;

View File

@ -19,23 +19,23 @@ typedef int64_t IterationCount;
class TestReporter : public benchmark::ConsoleReporter { class TestReporter : public benchmark::ConsoleReporter {
public: public:
virtual bool ReportContext(const Context& context) override { bool ReportContext(const Context& context) override {
return ConsoleReporter::ReportContext(context); return ConsoleReporter::ReportContext(context);
}; };
virtual void ReportRuns(const std::vector<Run>& report) override { void ReportRuns(const std::vector<Run>& report) override {
assert(report.size() == 1); assert(report.size() == 1);
ConsoleReporter::ReportRuns(report); ConsoleReporter::ReportRuns(report);
}; };
virtual void ReportRunsConfig(double min_time, bool /* has_explicit_iters */, void ReportRunsConfig(double min_time, bool /* has_explicit_iters */,
IterationCount /* iters */) override { IterationCount /* iters */) override {
min_times_.push_back(min_time); min_times_.push_back(min_time);
} }
TestReporter() {} TestReporter() {}
virtual ~TestReporter() {} ~TestReporter() override {}
const std::vector<double>& GetMinTimes() const { return min_times_; } const std::vector<double>& GetMinTimes() const { return min_times_; }

View File

@ -85,7 +85,7 @@ int main(int argc, char** argv) {
if (argc == 2) { if (argc == 2) {
// Make sure we ran all of the tests // Make sure we ran all of the tests
std::stringstream ss(argv[1]); std::stringstream ss(argv[1]);
int64_t expected_return; int64_t expected_return = 0;
ss >> expected_return; ss >> expected_return;
if (returned_count != expected_return) { if (returned_count != expected_return) {

View File

@ -83,7 +83,7 @@ std::string PerformSubstitutions(std::string source) {
SubMap const& subs = GetSubstitutions(); SubMap const& subs = GetSubstitutions();
using SizeT = std::string::size_type; using SizeT = std::string::size_type;
for (auto const& KV : subs) { for (auto const& KV : subs) {
SizeT pos; SizeT pos = 0;
SizeT next_start = 0; SizeT next_start = 0;
while ((pos = source.find(KV.first, next_start)) != std::string::npos) { while ((pos = source.find(KV.first, next_start)) != std::string::npos) {
next_start = pos + KV.second.size(); next_start = pos + KV.second.size();