aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.clang-tidy47
-rw-r--r--Makefile1
-rw-r--r--bitfield.h14
-rw-r--r--option.h2
-rw-r--r--test/option.cc26
-rw-r--r--test/timer.cc16
6 files changed, 77 insertions, 29 deletions
diff --git a/.clang-tidy b/.clang-tidy
new file mode 100644
index 0000000..a80c66b
--- /dev/null
+++ b/.clang-tidy
@@ -0,0 +1,47 @@
+HeaderFilterRegex: '.*'
+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
+Checks: >
+ -*,
+ clang-analyzer-*,
+ -clang-analyzer-cplusplus.Move,
+ performance-*,
+ portability-*,
+ concurrency-*,
+ modernize-*,
+ -modernize-use-trailing-return-type,
+ -modernize-avoid-c-arrays,
+ readability-reduntant-*,
+ readability-identifier-naming,
+ #misc-*,
+ #cert-*,
+ #bugprone-*,
+ #cppcoreguidelines-*,
+ #-cppcoreguidelines-avoid-magic-numbers,
+
+# readability-identifier-naming.* options:
+# https://clang.llvm.org/extra/clang-tidy/checks/readability/identifier-naming.html
+CheckOptions:
+ - { key: readability-identifier-naming.ClassCase, value: lower_case }
+ - { key: readability-identifier-naming.MethodCase, value: lower_case }
+ - { key: readability-identifier-naming.MemberCase, value: lower_case }
+ - { key: readability-identifier-naming.ProtectedMemberCase, value: lower_case }
+ - { key: readability-identifier-naming.ProtectedMemberPrefix, value: m_ }
+ - { key: readability-identifier-naming.PrivateMemberCase, value: lower_case }
+ - { key: readability-identifier-naming.PrivateMemberPrefix, value: m_ }
+
+ - { key: readability-identifier-naming.EnumConstantCase, value: CamelCase }
+ - { key: readability-identifier-naming.EnumConstantPrefix, value: k }
+ - { key: readability-identifier-naming.ConstantCase, value: CamelCase }
+ - { key: readability-identifier-naming.ConstantPrefix, value: k }
+ - { key: readability-identifier-naming.ConstantIgnoredRegexp, value: is_.*_v }
+
+ - { key: readability-identifier-naming.FunctionCase, value: lower_case }
+ - { key: readability-identifier-naming.ParameterCase, value: lower_case }
+ - { key: readability-identifier-naming.VariableCase, value: lower_case }
+
+ - { key: readability-identifier-naming.TemplateParameterCase, value: CamelCase }
+ - { key: readability-identifier-naming.MacroDefinitionCase, value: UPPER_CASE }
diff --git a/Makefile b/Makefile
index ceaa80e..05d7233 100644
--- a/Makefile
+++ b/Makefile
@@ -31,6 +31,7 @@ run: all
lint:
clang-format --dry-run -Werror $(shell find -name '*.cc' -o -name '*.h')
+ clang-tidy test/*.cc -- $(CXXFLAGS)
build/%: build/%.o
$(CXX) -o $@ $< $(LDFLAGS)
diff --git a/bitfield.h b/bitfield.h
index 833a722..9aafaf8 100644
--- a/bitfield.h
+++ b/bitfield.h
@@ -10,7 +10,7 @@ namespace impl {
* Constant check for supported underlying BITFILED types.
*/
template <typename ValueType>
-static constexpr bool is_bitfield_type =
+static constexpr bool is_bitfield_type_v =
std::is_integral<ValueType>::value && std::is_unsigned<ValueType>::value &&
!std::is_same<ValueType, bool>::value;
@@ -107,7 +107,7 @@ struct const_field_ref {
*/
template <typename ValueType = std::uint32_t>
struct bitfield {
- static_assert(impl::is_bitfield_type<ValueType>,
+ static_assert(impl::is_bitfield_type_v<ValueType>,
"bitfield instantiated with incorrect type");
constexpr explicit bitfield(ValueType val) : m_val{val} {}
@@ -177,11 +177,11 @@ struct bitfield {
// -- TESTS --------------------------------------------------------------------
-static_assert(impl::is_bitfield_type<std::uint32_t>, "");
-static_assert(!impl::is_bitfield_type<bool>, "");
-static_assert(!impl::is_bitfield_type<std::int32_t>, "");
-static_assert(!impl::is_bitfield_type<std::uint32_t*>, "");
-static_assert(!impl::is_bitfield_type<float>, "");
+static_assert(impl::is_bitfield_type_v<std::uint32_t>, "");
+static_assert(!impl::is_bitfield_type_v<bool>, "");
+static_assert(!impl::is_bitfield_type_v<std::int32_t>, "");
+static_assert(!impl::is_bitfield_type_v<std::uint32_t*>, "");
+static_assert(!impl::is_bitfield_type_v<float>, "");
static_assert(impl::compute_mask<0, 0, std::uint32_t>() == 0x1, "");
static_assert(impl::compute_mask<4, 7, std::uint32_t>() == 0xf0, "");
diff --git a/option.h b/option.h
index fd26acb..ab7a72e 100644
--- a/option.h
+++ b/option.h
@@ -37,7 +37,7 @@ struct option {
}
}
- constexpr option(option&& op) : m_has_value{op.has_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()));
diff --git a/test/option.cc b/test/option.cc
index 0417266..30b2406 100644
--- a/test/option.cc
+++ b/test/option.cc
@@ -2,31 +2,31 @@
#include <cstdio>
#include <cstdlib>
-struct Checker {
+struct checker {
static unsigned cnt;
- Checker() {
+ checker() {
++cnt;
}
- Checker(const Checker&) {
+ checker(const checker&) {
++cnt;
}
- Checker(Checker&&) {
+ checker(checker&&) noexcept {
++cnt;
}
- ~Checker() {
+ ~checker() {
--cnt;
}
};
-unsigned Checker::cnt = 0;
+unsigned checker::cnt = 0;
int main() {
using option::option;
auto check_cnt = [](unsigned expect) {
- if (expect != Checker::cnt) {
- std::printf("Checker: expect=%u cnt=%u\n", expect, Checker::cnt);
+ if (expect != checker::cnt) {
+ std::printf("Checker: expect=%u cnt=%u\n", expect, checker::cnt);
std::abort();
}
};
@@ -43,18 +43,18 @@ int main() {
check_cnt(0);
{
- option<Checker> o1(Checker{});
+ option<checker> o1(checker{});
// copy construct
- option<Checker> o2 = o1;
+ option<checker> o2 = o1;
// move construct
- option<Checker> o3 = o1.take();
+ option<checker> o3 = o1.take();
assert(!o1.has_value());
assert(o2.has_value());
assert(o3.has_value());
// move option
- option<Checker> o4 = std::move(o2);
+ option<checker> o4 = std::move(o2);
assert(!o2.has_value());
assert(o4.has_value());
@@ -74,7 +74,7 @@ int main() {
check_cnt(0);
{
- option<Checker> o1;
+ option<checker> o1;
assert(!o1.has_value());
o1.emplace();
diff --git a/test/timer.cc b/test/timer.cc
index 078c4bb..6bc783c 100644
--- a/test/timer.cc
+++ b/test/timer.cc
@@ -3,26 +3,26 @@
#include <cstdio>
int main() {
- timer::timer T;
+ timer::timer t;
- const auto show_time = [&T]() {
- std::fprintf(stderr, "usec=%f msec=%f sec=%f\n", T.as_usec(), T.as_msec(),
- T.as_sec());
+ const auto kShowTime = [&t]() {
+ std::fprintf(stderr, "usec=%f msec=%f sec=%f\n", t.as_usec(), t.as_msec(),
+ t.as_sec());
};
{
puts("Sleep 100ms");
- timer::scoped_timer s{T};
+ timer::scoped_timer s{t};
usleep(100 * 1000);
}
- show_time();
+ kShowTime();
{
puts("Sleep 500ms");
- timer::scoped_timer s{T};
+ timer::scoped_timer s{t};
usleep(500 * 1000);
}
- show_time();
+ kShowTime();
return 0;
}