diff options
-rw-r--r-- | .clang-tidy | 22 | ||||
-rw-r--r-- | bitfield.h | 7 | ||||
-rw-r--r-- | option.h | 8 | ||||
-rw-r--r-- | test/option.cc | 8 | ||||
-rw-r--r-- | test/timer.cc | 4 | ||||
-rw-r--r-- | 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 @@ -11,7 +11,8 @@ namespace impl { */ template <typename ValueType> static constexpr bool is_bitfield_type_v = - std::is_integral<ValueType>::value && std::is_unsigned<ValueType>::value && + std::is_integral<ValueType>::value && // NOLINT(misc-redundant-expression) + std::is_unsigned<ValueType>::value && // NOLINT(misc-redundant-expression) !std::is_same<ValueType, bool>::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<ValueType>& operator OP(ValueType val) { \ m_val OP val; \ return *this; \ @@ -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 <typename U = T> 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 <typename... Params> constexpr T& emplace(Params&&... params) { reset(); - new (m_value) T(std::forward<Params>(params)...); + new (&m_value) T(std::forward<Params>(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<int> o1; - option<int> o2{::option::none{}}; + const option<int> kO1{}; + const option<int> 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(); @@ -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; }; |