From 6823c5a7eced6ed2b198347be1a6ee90d89f496e Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Tue, 15 Aug 2023 22:12:33 +0900 Subject: [PATCH] Enable clang-tidy cppcoreguidelines (#2269) --- .clang-tidy | 19 ++++++++++++++++++- src/s3fs.cpp | 10 ++++++++++ test/truncate_read_file.cc | 2 +- test/write_multiblock.cc | 2 +- 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index e6f332f..ad25931 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -8,7 +8,24 @@ Checks: ' -bugprone-macro-parentheses, -bugprone-narrowing-conversions, -bugprone-unhandled-self-assignment, - cppcoreguidelines-pro-type-cstyle-cast, + cppcoreguidelines-*, + -cppcoreguidelines-avoid-c-arrays, + -cppcoreguidelines-avoid-do-while, + -cppcoreguidelines-avoid-magic-numbers, + -cppcoreguidelines-avoid-non-const-global-variables, + -cppcoreguidelines-init-variables, + -cppcoreguidelines-macro-usage, + -cppcoreguidelines-narrowing-conversions, + -cppcoreguidelines-no-malloc, + -cppcoreguidelines-owning-memory, + -cppcoreguidelines-pro-bounds-array-to-pointer-decay, + -cppcoreguidelines-pro-bounds-constant-array-index, + -cppcoreguidelines-pro-bounds-pointer-arithmetic, + -cppcoreguidelines-pro-type-const-cast, + -cppcoreguidelines-pro-type-member-init, + -cppcoreguidelines-pro-type-reinterpret-cast, + -cppcoreguidelines-pro-type-union-access, + -cppcoreguidelines-pro-type-vararg, google-*, -google-build-using-namespace, -google-readability-casting, diff --git a/src/s3fs.cpp b/src/s3fs.cpp index c6f4d4b..6923c86 100644 --- a/src/s3fs.cpp +++ b/src/s3fs.cpp @@ -206,9 +206,15 @@ class MpStatFlag mutable pthread_mutex_t flag_lock; bool is_lock_init; bool has_mp_stat; + public: MpStatFlag(); + MpStatFlag(const MpStatFlag&) = delete; + MpStatFlag(MpStatFlag&&) = delete; ~MpStatFlag(); + MpStatFlag& operator=(const MpStatFlag&) = delete; + MpStatFlag& operator=(MpStatFlag&&) = delete; + bool Get(); bool Set(bool flag); }; @@ -272,7 +278,11 @@ class SyncFiller public: explicit SyncFiller(void* buff = nullptr, fuse_fill_dir_t filler = nullptr); + SyncFiller(const SyncFiller&) = delete; + SyncFiller(SyncFiller&&) = delete; ~SyncFiller(); + SyncFiller& operator=(const SyncFiller&) = delete; + SyncFiller& operator=(SyncFiller&&) = delete; int Fill(const char *name, const struct stat *stbuf, off_t off); int SufficiencyFill(const std::vector& pathlist); diff --git a/test/truncate_read_file.cc b/test/truncate_read_file.cc index 1995b50..eb9697d 100644 --- a/test/truncate_read_file.cc +++ b/test/truncate_read_file.cc @@ -40,7 +40,7 @@ int main(int argc, char *argv[]) } const char* filepath = argv[1]; - off_t size = (off_t)strtoull(argv[2], NULL, 10); + off_t size = static_cast(strtoull(argv[2], nullptr, 10)); int fd; // open file diff --git a/test/write_multiblock.cc b/test/write_multiblock.cc index 0f2abdf..aaabc7b 100644 --- a/test/write_multiblock.cc +++ b/test/write_multiblock.cc @@ -171,7 +171,7 @@ static bool parse_arguments(int argc, char** argv, strlist_t& files, wbpart_list while(-1 != (opt = getopt(argc, argv, "f:p:"))){ switch(opt){ case 'f': - files.push_back(std::string(optarg)); + files.emplace_back(optarg); break; case 'p': if(!parse_write_blocks(optarg, wbparts, max_size)){