aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Stoelp <johannes.stoelp@gmail.com>2023-08-17 23:36:53 +0200
committerJohannes Stoelp <johannes.stoelp@gmail.com>2023-08-17 23:36:53 +0200
commit6c9695d16c157e9119dcf897266e8643e6565213 (patch)
tree6f96470fb1a56234f18c1561f3b96eb301fffe1c
parent851d4fb9db087eeb183f1c1cb5d96829a32e690b (diff)
downloadcpp-utils-6c9695d16c157e9119dcf897266e8643e6565213.tar.gz
cpp-utils-6c9695d16c157e9119dcf897266e8643e6565213.zip
enable misc-*,bugprone-* lints
-rw-r--r--.clang-tidy22
-rw-r--r--bitfield.h7
-rw-r--r--option.h8
-rw-r--r--test/option.cc8
-rw-r--r--test/timer.cc4
-rw-r--r--timer.h5
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 <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; \
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 <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();
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;
};