From 6c9695d16c157e9119dcf897266e8643e6565213 Mon Sep 17 00:00:00 2001 From: Johannes Stoelp Date: Thu, 17 Aug 2023 23:36:53 +0200 Subject: enable misc-*,bugprone-* lints --- .clang-tidy | 22 +++++++++++++++++++--- bitfield.h | 7 +++++-- option.h | 8 ++++---- test/option.cc | 8 ++++---- test/timer.cc | 4 ++-- timer.h | 5 +++++ 6 files changed, 39 insertions(+), 15 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index a80c66b..ac2683b 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -4,6 +4,21 @@ WarningsAsErrors: '*' # Available checks: # https://clang.llvm.org/extra/clang-tidy/index.html#using-clang-tidy # https://clang.llvm.org/extra/clang-tidy/checks/list.html +# +# List all checks: +# clang-tidy --checks="*" --list-checks +# +# Excuse all lints for a line inside the source code: +# some code; // NOLINT +# +# // NOLINTNEXTLINE +# some code; +# +# Excuse a single lint for a line inside the source code: +# some code; // NOLINT(bugprone-macro-parentheses) +# +# // NOLINTNEXTLINE(bugprone-macro-parentheses) +# some code; Checks: > -*, clang-analyzer-*, @@ -16,11 +31,12 @@ Checks: > -modernize-avoid-c-arrays, readability-reduntant-*, readability-identifier-naming, - #misc-*, + misc-*, + -misc-non-private-member-variables-in-classes, #cert-*, - #bugprone-*, + bugprone-*, + -bugprone-use-after-move, #cppcoreguidelines-*, - #-cppcoreguidelines-avoid-magic-numbers, # readability-identifier-naming.* options: # https://clang.llvm.org/extra/clang-tidy/checks/readability/identifier-naming.html diff --git a/bitfield.h b/bitfield.h index 9aafaf8..850a326 100644 --- a/bitfield.h +++ b/bitfield.h @@ -11,7 +11,8 @@ namespace impl { */ template static constexpr bool is_bitfield_type_v = - std::is_integral::value && std::is_unsigned::value && + std::is_integral::value && // NOLINT(misc-redundant-expression) + std::is_unsigned::value && // NOLINT(misc-redundant-expression) !std::is_same::value; /** @@ -56,7 +57,8 @@ struct field_ref { constexpr field_ref& operator=(ValueType val) { m_val &= ~kMask; - return operator|=(val); + operator|=(val); + return *this; } constexpr field_ref& operator|=(ValueType val) { @@ -121,6 +123,7 @@ struct bitfield { } #define OPERATOR(OP) \ + /* NOLINTNEXTLINE(bugprone-macro-parentheses) */ \ constexpr bitfield& operator OP(ValueType val) { \ m_val OP val; \ return *this; \ diff --git a/option.h b/option.h index ab7a72e..47a0624 100644 --- a/option.h +++ b/option.h @@ -33,20 +33,20 @@ struct option { constexpr option(const option& op) : m_has_value{op.has_value()} { if (op.has_value()) { // Copy construct from inner VALUE of OP. - new (m_value) T(op.value()); + new (&m_value) T(op.value()); } } constexpr option(option&& op) noexcept : m_has_value{op.has_value()} { if (op.m_has_value) { // Move construct from inner VALUE of OP. - new (m_value) T(std::move(op.take())); + new (&m_value) T(std::move(op.take())); } } template constexpr option(T&& val) : m_has_value{true} { - new (m_value) T(std::move(val)); + new (&m_value) T(std::move(val)); } // -- DESTRUCTOR ------------------------------------------------------------- @@ -60,7 +60,7 @@ struct option { template constexpr T& emplace(Params&&... params) { reset(); - new (m_value) T(std::forward(params)...); + new (&m_value) T(std::forward(params)...); m_has_value = true; return value(); } diff --git a/test/option.cc b/test/option.cc index 30b2406..cf80374 100644 --- a/test/option.cc +++ b/test/option.cc @@ -32,11 +32,11 @@ int main() { }; { - option o1; - option o2{::option::none{}}; + const option kO1{}; + const option kO2{::option::none{}}; - assert(!o1.has_value()); - assert(!o2.has_value()); + assert(!kO1.has_value()); + assert(!kO2.has_value()); } // Assume we start test with cnt=0. diff --git a/test/timer.cc b/test/timer.cc index 6bc783c..5ac169c 100644 --- a/test/timer.cc +++ b/test/timer.cc @@ -12,14 +12,14 @@ int main() { { puts("Sleep 100ms"); - timer::scoped_timer s{t}; + const timer::scoped_timer kS{t}; usleep(100 * 1000); } kShowTime(); { puts("Sleep 500ms"); - timer::scoped_timer s{t}; + const timer::scoped_timer kS{t}; usleep(500 * 1000); } kShowTime(); diff --git a/timer.h b/timer.h index 933c02c..ce0e629 100644 --- a/timer.h +++ b/timer.h @@ -45,6 +45,11 @@ struct scoped_timer { m_timer.stop(); } + scoped_timer(const scoped_timer&) = delete; + scoped_timer& operator=(const scoped_timer&) = delete; + scoped_timer(scoped_timer&&) = delete; + scoped_timer& operator=(scoped_timer&&) = delete; + private: timer& m_timer; }; -- cgit v1.2.3