]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Enable more clang-tidy rules and implement suggestions
authorJoel Rosdahl <joel@rosdahl.net>
Fri, 19 Jun 2020 17:48:19 +0000 (19:48 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Tue, 23 Jun 2020 19:44:45 +0000 (21:44 +0200)
12 files changed:
src/.clang-tidy
src/Config.cpp
src/InodeCache.cpp
src/Util.cpp
src/Util.hpp
src/cleanup.cpp
src/compopt.cpp
src/hash.cpp
src/legacy_util.cpp
src/manifest.cpp
src/result.cpp
src/stats.cpp

index 60fc47ee5936253f4eaddd70331da0108b9f3f9f..e0a0ace9eb3c9316cb5962a5d36ef7e4adae2b17 100644 (file)
@@ -13,23 +13,14 @@ Checks:          '-*,
                   -readability-implicit-bool-conversion,
                   -readability-magic-numbers,
                   -readability-else-after-return,
-                  -readability-named-parameter,
                   -readability-qualified-auto,
                   -readability-magic-numbers,
-                  -readability-isolate-declaration,
-                  -readability-inconsistent-declaration-parameter-name,
-                  -readability-simplify-boolean-expr,
                   performance-*,
                   -performance-unnecessary-value-param,
-                  -performance-faster-string-find,
                   modernize-*,
                   -modernize-avoid-c-arrays,
-                  -modernize-deprecated-headers,
-                  -modernize-loop-convert,
                   -modernize-pass-by-value,
                   -modernize-use-auto,
-                  -modernize-use-bool-literals,
-                  -modernize-use-using,
                   -modernize-use-trailing-return-type,
                   cppcoreguidelines-*,
                   -cppcoreguidelines-pro-bounds-array-to-pointer-decay,
@@ -41,8 +32,6 @@ Checks:          '-*,
                   -cppcoreguidelines-init-variables,
                   -cppcoreguidelines-avoid-c-arrays,
                   -cppcoreguidelines-pro-bounds-constant-array-index,
-                  -cppcoreguidelines-pro-type-cstyle-cast,
-                  -cppcoreguidelines-avoid-goto,
                   -cppcoreguidelines-pro-type-member-init,
                   -cppcoreguidelines-macro-usage,
                   -cppcoreguidelines-pro-type-const-cast,
index 575dec5673bc49281de738609435f9e7a656981e..cab2aa71a41e04adeb03f239d5417c28513efa8e 100644 (file)
@@ -380,7 +380,7 @@ parse_line(const std::string& line,
   if (stripped_line.empty() || stripped_line[0] == '#') {
     return true;
   }
-  size_t equal_pos = stripped_line.find("=");
+  size_t equal_pos = stripped_line.find('=');
   if (equal_pos == std::string::npos) {
     *error_message = "missing equal sign";
     return false;
index 2b1d992992a0d759093b42bc3c777c62999d85ec..e73c35b460cd93523d4b6fd5eeb84222cff6e7ac 100644 (file)
@@ -294,8 +294,8 @@ InodeCache::create_new_file(const std::string& filename)
 #  ifdef PTHREAD_MUTEX_ROBUST
   pthread_mutexattr_setrobust(&mattr, PTHREAD_MUTEX_ROBUST);
 #  endif
-  for (uint32_t i = 0; i < k_num_buckets; ++i) {
-    pthread_mutex_init(&sr->buckets[i].mt, &mattr);
+  for (auto& bucket : sr->buckets) {
+    pthread_mutex_init(&bucket.mt, &mattr);
   }
 
   munmap(sr, sizeof(SharedRegion));
index bfac8ebbef7379162948c33fad14f7dfcf9e8c42..488631fc0065fd3e1b517170a031f630d0252fde 100644 (file)
@@ -196,7 +196,8 @@ edit_ansi_csi_seqs(string_view string, const SubstringEditor& editor)
 {
   static const std::regex csi_regex(
     "\x1B\\[[\x30-\x3F]*[\x20-\x2F]*[\x40-\x7E]");
-  std::string ret, substr;
+  std::string ret;
+  std::string substr;
   ret.reserve(string.size());
   for (std::cregex_token_iterator itr(
          string.begin(), string.end(), csi_regex, {-1, 0});
@@ -709,15 +710,15 @@ remove_extension(string_view path)
 }
 
 std::vector<string_view>
-split_into_views(string_view s, const char* separators)
+split_into_views(string_view input, const char* separators)
 {
-  return split_at<string_view>(s, separators);
+  return split_at<string_view>(input, separators);
 }
 
 std::vector<std::string>
-split_into_strings(string_view s, const char* separators)
+split_into_strings(string_view input, const char* separators)
 {
-  return split_at<std::string>(s, separators);
+  return split_at<std::string>(input, separators);
 }
 
 bool
@@ -730,7 +731,7 @@ std::string
 strip_ansi_csi_seqs(string_view string, string_view strip_actions)
 {
   return edit_ansi_csi_seqs(
-    string, [strip_actions](string_view::size_type, std::string& substr) {
+    string, [=](string_view::size_type /*pos*/, std::string& substr) {
       if (strip_actions.find(substr.back()) != string_view::npos) {
         substr.clear();
       }
index 8661a7107f3432162d13533cfafcb447c35ee390..a879080f5b53cf853c0defefc214d10c31a9d890 100644 (file)
@@ -33,7 +33,7 @@
 
 namespace Util {
 
-using ProgressReceiver = std::function<void(double)>;
+using ProgressReceiver = std::function<void(double /*progress*/)>;
 using CacheFileVisitor = std::function<void(std::shared_ptr<CacheFile>)>;
 using SubdirVisitor =
   std::function<void(const std::string& /*dir_path*/,
index 28b59fa42af0a2bbdda6667fda97cbd488df0611..e2a720a33b610e40d1aaf323f17f97a4490ad950 100644 (file)
@@ -28,7 +28,7 @@
 #include "stats.hpp"
 
 #include <algorithm>
-#include <math.h>
+#include <cmath>
 
 static void
 delete_file(const std::string& path,
index f1b29aeff981b0a2b8c2262a1f8b8f55fc08768c..67748c1ade46e4c8d510affb0b5a2931fa0f0491 100644 (file)
@@ -134,16 +134,16 @@ static const struct compopt compopts[] = {
 static int
 compare_compopts(const void* key1, const void* key2)
 {
-  const struct compopt* opt1 = (const struct compopt*)key1;
-  const struct compopt* opt2 = (const struct compopt*)key2;
+  const struct compopt* opt1 = static_cast<const struct compopt*>(key1);
+  const struct compopt* opt2 = static_cast<const struct compopt*>(key2);
   return strcmp(opt1->name, opt2->name);
 }
 
 static int
 compare_prefix_compopts(const void* key1, const void* key2)
 {
-  const struct compopt* opt1 = (const struct compopt*)key1;
-  const struct compopt* opt2 = (const struct compopt*)key2;
+  const struct compopt* opt1 = static_cast<const struct compopt*>(key1);
+  const struct compopt* opt2 = static_cast<const struct compopt*>(key2);
   return strncmp(opt1->name, opt2->name, strlen(opt2->name));
 }
 
index c843b685cb920a88c72eb3c5de61f07a052d7137..4d8ba65b4e585f4ce9eca9c7649ae168a4a138bc 100644 (file)
@@ -160,7 +160,7 @@ hash_string_buffer(struct hash* hash, const char* s, size_t length)
 void
 hash_int(struct hash* hash, int x)
 {
-  do_hash_buffer(hash, (char*)&x, sizeof(x));
+  do_hash_buffer(hash, reinterpret_cast<const char*>(&x), sizeof(x));
 
   char buf[16];
   snprintf(buf, sizeof(buf), "%d", x);
index d4c88652da2870fb2ceb6d92052c0d8316f2f6a0..0f08c5bd35614e01f005a6074b6cf2fd9ed3e4c6 100644 (file)
@@ -458,13 +458,13 @@ get_extension(const char* path)
 
 // Format a size as a human-readable string. Caller frees.
 char*
-format_human_readable_size(uint64_t v)
+format_human_readable_size(uint64_t size)
 {
   char* s;
-  if (v >= 1000 * 1000 * 1000) {
-    s = format("%.1f GB", v / ((double)(1000 * 1000 * 1000)));
+  if (size >= 1000 * 1000 * 1000) {
+    s = format("%.1f GB", size / ((double)(1000 * 1000 * 1000)));
   } else {
-    s = format("%.1f MB", v / ((double)(1000 * 1000)));
+    s = format("%.1f MB", size / ((double)(1000 * 1000)));
   }
   return s;
 }
@@ -636,15 +636,12 @@ same_executable_name(const char* s1, const char* s2)
 bool
 is_full_path(const char* path)
 {
-  if (strchr(path, '/')) {
-    return true;
-  }
 #ifdef _WIN32
   if (strchr(path, '\\')) {
     return true;
   }
 #endif
-  return false;
+  return strchr(path, '/');
 }
 
 // Update the modification time of a file in the cache to save it from LRU
index e4294cd63233f32d2eff015c278d7c67d08c13fb..87abeb938f38bd9e06587984b0473e0a937a1c73 100644 (file)
@@ -380,8 +380,8 @@ write_manifest(const Config& config,
   writer.write<uint32_t>(mf.results.size());
   for (const auto& result : mf.results) {
     writer.write<uint32_t>(result.file_info_indexes.size());
-    for (uint32_t j = 0; j < result.file_info_indexes.size(); ++j) {
-      writer.write(result.file_info_indexes[j]);
+    for (auto index : result.file_info_indexes) {
+      writer.write(index);
     }
     writer.write(result.name.bytes(), Digest::size());
   }
index 366405a0037b443687bf5a17eba2c4faa1ae1b9f..ad858a873cc1d7435c415f15793cefd68d71f107 100644 (file)
@@ -138,7 +138,7 @@ UnderlyingFileTypeIntToString(UnderlyingFileTypeInt underlying_type)
 }
 
 static void
-read_embedded_file_entry(const Context&,
+read_embedded_file_entry(const Context& /*ctx*/,
                          CacheEntryReader& reader,
                          const std::string& /*result_path_in_cache*/,
                          uint32_t entry_number,
@@ -358,7 +358,7 @@ read_result(const Context& ctx,
 }
 
 static void
-write_embedded_file_entry(Context&,
+write_embedded_file_entry(Context& /*ctx*/,
                           CacheEntryWriter& writer,
                           const std::string& /*result_path_in_cache*/,
                           uint32_t entry_number,
index 6ffb0bc39c93309700622b5ce64c0e93bade2c68..6676f55207041b44052d552bf0be8a6ca672a04a 100644 (file)
@@ -195,7 +195,7 @@ format_timestamp(uint64_t timestamp)
 {
   if (timestamp > 0) {
     struct tm tm;
-    localtime_r((time_t*)&timestamp, &tm);
+    localtime_r(reinterpret_cast<time_t*>(&timestamp), &tm);
     char buffer[100];
     strftime(buffer, sizeof(buffer), "%c", &tm);
     return format("    %s", buffer);
@@ -295,9 +295,9 @@ stats_update_size(Counters& counters, int64_t size, int files)
 
 // Read in the stats from one directory and add to the counters.
 void
-stats_read(const std::string& sfile, Counters& counters)
+stats_read(const std::string& path, Counters& counters)
 {
-  char* data = read_text_file(sfile.c_str(), 1024);
+  char* data = read_text_file(path.c_str(), 1024);
   if (data) {
     parse_stats(counters, data);
   }
@@ -371,7 +371,7 @@ stats_flush_to_file(const Config& config,
     double factor = config.limit_multiple() / 16;
     uint64_t max_size = round(config.max_size() * factor);
     uint32_t max_files = round(config.max_files() * factor);
-    clean_up_dir(subdir, max_size, max_files, [](double) {});
+    clean_up_dir(subdir, max_size, max_files, [](double /*progress*/) {});
   }
 }