Skip to content

Commit

Permalink
Setup clang-tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
StarQTius committed Dec 31, 2023
1 parent cccd831 commit f042a4c
Show file tree
Hide file tree
Showing 20 changed files with 71 additions and 11 deletions.
4 changes: 3 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Checks: '
modernize-*,
performance-*,
portability-*,
readbility-*'
readbility-*,
-cppcoreguidelines-avoid-c-arrays,
-modernize-avoid-c-arrays'
WarningsAsErrors: '*'
HeaderFilterRegex: '.*include/upd/.*'
5 changes: 3 additions & 2 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
name: Check code quality
on: push
jobs:
check-format:
check-lint:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ${{github.workspace}}
steps:
- uses: actions/checkout@v2
- run: sudo apt install clang-format
- run: sudo apt install clang-format clang-tidy
- run: pip install cmakelang
- run: clang-format --dry-run $(git ls-files | grep -E "\.(hpp|cpp)$")
- run: cmake-format --check $(git ls-files | grep -E "(CMakeLists.txt|\.cmake)$")
- run: cmake -B ${{github.workspace}}/build
- run: cmake --build build -t iwyu
- run: git ls-files | grep -E "\.(hpp|cpp)$" | xargs clang-tidy -p ${{github.workspace}}/build --extra-arg="-std=c++17" --extra-arg="-I${{github.workspace}}/include" --use-color
check-gcc-11:
runs-on: ubuntu-latest
steps:
Expand Down
10 changes: 5 additions & 5 deletions include/upd/basic_tuple.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ constexpr inline bool is_iterable_v = is_iterable<T>::value;
} // namespace detail

template<typename T, detail::require_is_serializable<T> = 0>
constexpr std::size_t serialization_size_impl(...) {
constexpr auto serialization_size_impl(...) -> std::size_t {
return sizeof(T);
}

template<typename T, detail::require_is_user_serializable<T> = 0>
constexpr std::size_t serialization_size_impl(int) {
constexpr auto serialization_size_impl(int) -> std::size_t {
using namespace upd::detail;

return decltype(make_view_for<endianess::LITTLE, signed_mode::TWOS_COMPLEMENT>(
Expand Down Expand Up @@ -87,7 +87,7 @@ class basic_tuple {
}

template<typename F>
decltype(auto) invoke(F &&f) const {
auto invoke(F &&f) const -> decltype(auto) {
return invoke_on_some(UPD_FWD(f), std::make_index_sequence<sizeof...(Ts)>{});
}

Expand Down Expand Up @@ -119,7 +119,7 @@ class basic_tuple {
} else if constexpr (std::is_signed_v<T>) {
return m_serializer.deserialize_signed(m_storage.data() + offset, sizeof(T));
} else if constexpr (std::is_array_v<T>) {
using element_t = std::remove_reference_t<decltype(*std::declval<T>())>;
using element_t = std::remove_pointer_t<std::decay_t<T>>;
using retval_t = std::array<element_t, sizeof(T) / sizeof(element_t)>;

retval_t retval{};
Expand All @@ -139,7 +139,7 @@ class basic_tuple {
}

template<typename F, std::size_t... Is>
decltype(auto) invoke_on_some(F &&f, std::index_sequence<Is...>) const {
auto invoke_on_some(F &&f, std::index_sequence<Is...>) const -> decltype(auto) {
return std::invoke(UPD_FWD(f), get(index_type_v<Is>)...);
}

Expand Down
4 changes: 4 additions & 0 deletions include/upd/detail/endianess.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include "../upd.hpp"
#include "type_traits/require.hpp"

// NOLINTBEGIN

namespace upd {
namespace detail {

Expand Down Expand Up @@ -73,3 +75,5 @@ void to_endianess(byte_t *raw_data, const T &x, std::size_t n) {

} // namespace detail
} // namespace upd

// NOLINTEND
4 changes: 4 additions & 0 deletions include/upd/detail/serialization.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include "type_traits/require.hpp"
#include "type_traits/signature.hpp"

// NOLINTBEGIN

namespace upd {

template<typename It, endianess Endianess, signed_mode Signed_Mode, typename... Args>
Expand Down Expand Up @@ -195,3 +197,5 @@ using require_is_serializable = require<is_serializable<T>::value, U>;

} // namespace detail
} // namespace upd

// NOLINTEND
4 changes: 4 additions & 0 deletions include/upd/detail/signed_representation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include "../upd.hpp"
#include "type_traits/require.hpp"

// NOLINTBEGIN

namespace upd {
namespace detail {

Expand Down Expand Up @@ -79,3 +81,5 @@ unsigned long long to_signed_mode(T value) {

} // namespace detail
} // namespace upd

// NOLINTEND
4 changes: 4 additions & 0 deletions include/upd/detail/type_traits/detector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include <type_traits> // IWYU pragma: keep

// NOLINTBEGIN

//! \brief Make a detector function which implements the Detection Idiom
//!
//! A detector is a template of `constexpr` functions which return a `bool` value wrapped in a `std::integral_constant`.
Expand All @@ -14,3 +16,5 @@
std::true_type NAME(int); \
template<TEMPLATE_PARAMETERS> \
std::false_type NAME(...);

// NOLINTEND
4 changes: 4 additions & 0 deletions include/upd/detail/type_traits/index_sequence.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <utility>
#endif // __cplusplus >= 201402L

// NOLINTBEGIN

namespace upd {
namespace detail {

Expand Down Expand Up @@ -42,3 +44,5 @@ struct make_index_sequence<0, Is...> : index_sequence<Is...> {};

} // namespace detail
} // namespace upd

// NOLINTEND
4 changes: 4 additions & 0 deletions include/upd/detail/type_traits/is_array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <cstddef>
#include <type_traits>

// NOLINTBEGIN

namespace upd {
namespace detail {

Expand All @@ -23,3 +25,5 @@ struct is_array<std::array<T, N>> : std::true_type {};

} // namespace detail
} // namespace upd

// NOLINTEND
4 changes: 4 additions & 0 deletions include/upd/detail/type_traits/is_keyring.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

// IWYU pragma: no_forward_declare unevaluated

// NOLINTBEGIN

namespace upd {

template<endianess, signed_mode, typename...>
Expand All @@ -26,3 +28,5 @@ struct is_keyring : decltype(is_keyring_impl(std::declval<T>())) {};

} // namespace detail
} // namespace upd

// NOLINTEND
4 changes: 4 additions & 0 deletions include/upd/detail/type_traits/is_user_serializable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "../../upd.hpp"
#include "detector.hpp"

// NOLINTBEGIN

namespace upd {
namespace detail {

Expand All @@ -20,3 +22,5 @@ struct is_user_serializable : std::integral_constant<bool, decltype(is_not_user_

} // namespace detail
} // namespace upd

// NOLINTEND
4 changes: 4 additions & 0 deletions include/upd/detail/type_traits/require.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include "signature.hpp"
#include "typelist.hpp"

// NOLINTBEGIN

#if !defined(DOXYGEN)

#define UPD_REQUIRE(...) ::upd::detail::require<__VA_ARGS__> = 0
Expand Down Expand Up @@ -128,3 +130,5 @@ using require_key = require<is_key<T>::value, U>;

} // namespace detail
} // namespace upd

// NOLINTEND
4 changes: 4 additions & 0 deletions include/upd/detail/type_traits/signature.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include "detector.hpp"
#include "typelist.hpp"

// NOLINTBEGIN

namespace upd {
namespace detail {

Expand Down Expand Up @@ -145,3 +147,5 @@ struct has_signature<F, R(Args...)> : decltype(has_signature_impl<F, R, Args...>

} // namespace detail
} // namespace upd

// NOLINTEND
1 change: 1 addition & 0 deletions include/upd/detail/type_traits/ternary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#pragma once

// NOLINTNEXTLINE(modernize-concat-nested-namespaces)
namespace upd {
namespace detail {

Expand Down
5 changes: 5 additions & 0 deletions include/upd/detail/type_traits/typelist.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@

#include "ternary.hpp" // IWYU pragma: keep

// NOLINTBEGIN

#if __cplusplus >= 201703L
#include "index_sequence.hpp"
#endif // __cplusplus >= 201703L

// NOLINTNEXTLINE(modernize-concat-nested-namespaces)
namespace upd {
namespace detail {

Expand Down Expand Up @@ -264,3 +267,5 @@ using max_p = max<tlist_t<Ts...>>;

} // namespace detail
} // namespace upd

// NOLINTEND
4 changes: 2 additions & 2 deletions include/upd/detail/variadic/leaf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ namespace upd::detail::variadic {

template<std::size_t I, typename T>
struct leaf {
constexpr static T *at(index_type<I>) noexcept;
constexpr static index_type<I> find(T *) noexcept;
constexpr static auto at(index_type<I>) noexcept -> T *;
constexpr static auto find(T *) noexcept -> index_type<I>;
};

} // namespace upd::detail::variadic
4 changes: 4 additions & 0 deletions include/upd/unevaluated.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#pragma once

// NOLINTBEGIN

//! \brief Bind an object with static storage duration to a compile-time reference
//! \related unevaluated
#define UPD_CTREF(VALUE) \
Expand All @@ -21,3 +23,5 @@ struct unevaluated {
};

} // namespace upd

// NOLINTEND
4 changes: 4 additions & 0 deletions include/upd/upd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include "format.hpp"

// NOLINTBEGIN

#define UPD_FWD(x) static_cast<decltype(x) &&>(x)
#define UPD_PACK(...) __VA_ARGS__
#define UPD_SCOPE_OPERATOR(LHS, RHS) LHS::RHS
Expand Down Expand Up @@ -38,3 +40,5 @@ template<typename>
struct upd_extension; // IWYU pragma: keep

namespace upd::detail {};

// NOLINTEND
4 changes: 4 additions & 0 deletions test/basic_tuple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <fakeit.hpp>
#include <upd/basic_tuple.hpp>

// NOLINTBEGIN

using namespace fakeit;

struct serializer_interface {
Expand Down Expand Up @@ -96,3 +98,5 @@ TEST_CASE("Testing a basic_tuple that contains a few integers", "[basic_tuple]")
}
}
}

// NOLINTEND
1 change: 0 additions & 1 deletion test/py/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
os.environ["CPPFLAGS"] = "-I" + str(Path(__file__).parent.parent.parent) + "/include"

import pytest

import unpadded as upd

pytest_plugins = ("pytest_asyncio",)
Expand Down

0 comments on commit f042a4c

Please sign in to comment.