Skip to content

Commit c2ade80

Browse files
authored
Tidy clang (#179)
* Fix first set of clang-tidy warnings * Resolve 'cppcoreguidelines-pro-type-member-init' clang-tidy warnings * Address cppcoreguidelines-avoid-magic-numbers warnings * Replace forward with move * Fix some readability issues * Set enum size * Fix some naming issues
1 parent a7ceaf4 commit c2ade80

40 files changed

Lines changed: 557 additions & 510 deletions

.clang-tidy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Checks: >
55
bugprone-*,
66
-bugprone-exception-escape,
77
-bugprone-easily-swappable-parameters,
8+
-bugprone-branch-clone,
89
clang-diagnostic-*,
910
clang-analyzer-*,
1011
concurrency-*,
@@ -17,6 +18,7 @@ Checks: >
1718
-cppcoreguidelines-avoid-c-arrays,
1819
-cppcoreguidelines-avoid-do-while,
1920
-cppcoreguidelines-pro-type-reinterpret-cast,
21+
-cppcoreguidelines-missing-std-forward,
2022
misc-*,
2123
-misc-unused-parameters,
2224
-misc-non-private-member-variables-in-classes,

.github/workflows/clang-tidy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ jobs:
5454
- name: Run clang-tidy on source files
5555
if: false # Disabled for now
5656
run: |
57-
find tests -name '*.cpp' -print0 | \
57+
find examples -name '*.cpp' -print0 | \
5858
xargs -0 -n1 -P$(nproc) clang-tidy-21 -p build
5959
6060
- name: clang-tidy check passed

.github/workflows/documentation.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ jobs:
4343
run: |
4444
git clone https://github.com/Microsoft/vcpkg.git
4545
./vcpkg/bootstrap-vcpkg.sh
46+
vcpkg install nlohmann-json
4647
4748
- name: Configure CMake
4849
run: |
@@ -51,6 +52,8 @@ jobs:
5152
-G Ninja \
5253
-DCMAKE_BUILD_TYPE=Release \
5354
-DCMAKE_TOOLCHAIN_FILE=${{ github.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake \
55+
-Dskyr_BUILD_TESTS=OFF \
56+
-Dskyr_BUILD_DOCS=ON \
5457
.
5558
5659
- name: Build documentation

include/skyr/concepts/url_concepts.hpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,22 @@
1111
#include <type_traits>
1212

1313
namespace skyr {
14-
template <class T, class charT>
15-
concept is_basic_string = std::is_same_v<std::remove_cv_t<T>, std::basic_string<charT>>;
14+
template <class T, class CharT>
15+
concept is_basic_string = std::is_same_v<std::remove_cv_t<T>, std::basic_string<CharT>>;
1616

17-
template <class T, class charT>
18-
concept is_basic_string_view = std::is_same_v<std::remove_cv_t<T>, std::basic_string_view<charT>>;
17+
template <class T, class CharT>
18+
concept is_basic_string_view = std::is_same_v<std::remove_cv_t<T>, std::basic_string_view<CharT>>;
1919

20-
template <class T, class charT>
20+
template <class T, class CharT>
2121
concept is_char_array =
22-
std::conjunction_v<std::is_array<T>, std::is_same<std::remove_cv_t<std::remove_extent_t<T>>, charT>>;
22+
std::conjunction_v<std::is_array<T>, std::is_same<std::remove_cv_t<std::remove_extent_t<T>>, CharT>>;
2323

24-
template <class T, class charT>
25-
concept is_char_pointer = std::conjunction_v<std::is_pointer<T>, std::is_same<std::remove_pointer_t<T>, charT>>;
24+
template <class T, class CharT>
25+
concept is_char_pointer = std::conjunction_v<std::is_pointer<T>, std::is_same<std::remove_pointer_t<T>, CharT>>;
2626

27-
template <class T, class charT>
27+
template <class T, class CharT>
2828
concept is_string_container =
29-
is_basic_string<T, charT> || is_basic_string_view<T, charT> || is_char_array<T, charT> || is_char_pointer<T, charT>;
29+
is_basic_string<T, CharT> || is_basic_string_view<T, CharT> || is_char_array<T, CharT> || is_char_pointer<T, CharT>;
3030

3131
template <typename T>
3232
concept is_u8_convertible =

include/skyr/containers/static_vector.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace skyr {
2020
template <class T, std::size_t Capacity>
2121
class static_vector {
2222
private:
23-
alignas(T) std::array<std::byte, sizeof(T) * Capacity> storage_;
23+
alignas(T) std::array<std::byte, sizeof(T) * Capacity> storage_{};
2424
std::size_t size_ = 0;
2525

2626
auto data_ptr() noexcept -> T* {

include/skyr/core/check_input.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,18 @@ constexpr static auto is_c0_control_or_space = [](auto byte) {
1616
return std::iscntrl(byte, std::locale::classic()) || std::isspace(byte, std::locale::classic());
1717
};
1818

19-
constexpr inline auto remove_leading_c0_control_or_space(std::string_view input, bool* validation_error) {
20-
auto first = std::cbegin(input), last = std::cend(input);
19+
constexpr auto remove_leading_c0_control_or_space(std::string_view input, bool* validation_error) {
20+
auto first = std::cbegin(input);
21+
auto last = std::cend(input);
2122
auto it = std::find_if_not(first, last, is_c0_control_or_space);
2223
*validation_error |= (it != first);
2324
input.remove_prefix(std::distance(first, it));
2425
return input;
2526
}
2627

27-
constexpr inline auto remove_trailing_c0_control_or_space(std::string_view input, bool* validation_error) {
28-
auto first = std::crbegin(input), last = std::crend(input);
28+
constexpr auto remove_trailing_c0_control_or_space(std::string_view input, bool* validation_error) {
29+
auto first = std::crbegin(input);
30+
auto last = std::crend(input);
2931
auto it = std::find_if_not(first, last, is_c0_control_or_space);
3032
*validation_error |= (it != first);
3133
input.remove_suffix(std::distance(first, it));

include/skyr/core/errors.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
#ifndef SKYR_CORE_ERRORS_HPP
77
#define SKYR_CORE_ERRORS_HPP
88

9+
#include <cstdint>
910
#include <system_error>
1011

1112
namespace skyr {
1213
/// \enum url_parse_errc
1314
/// Enumerates URL parser errors
14-
enum class url_parse_errc {
15+
enum class url_parse_errc : std::uint8_t {
1516
/// The string contains an invalid Unicode character
1617
invalid_unicode_character = 1,
1718
/// A character is not a valid scheme character

include/skyr/core/host.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,17 @@ class host {
6767
///
6868
/// \return The host as a string
6969
[[nodiscard]] auto serialize() const {
70-
constexpr static auto serialize = [](auto&& host) -> std::string {
71-
using T = std::decay_t<decltype(host)>;
70+
constexpr static auto serialize = []<typename T>(T&& host) -> std::string {
71+
using host_t = std::decay_t<T>;
7272

73-
if constexpr (std::is_same_v<T, ipv4_address>) {
73+
if constexpr (std::is_same_v<host_t, ipv4_address>) {
7474
return host.serialize();
75-
} else if constexpr (std::is_same_v<T, ipv6_address>) {
75+
} else if constexpr (std::is_same_v<host_t, ipv6_address>) {
7676
return std::format("[{}]", host.serialize());
77-
} else if constexpr (std::is_same_v<T, domain_name> || std::is_same_v<T, opaque_host>) {
77+
} else if constexpr (std::is_same_v<host_t, domain_name> || std::is_same_v<host_t, opaque_host>) {
7878
return host.name;
7979
} else {
80-
return std::string();
80+
return {};
8181
}
8282
};
8383

@@ -139,7 +139,7 @@ class host {
139139
}
140140

141141
private:
142-
host_types host_;
142+
host_types host_{};
143143
};
144144

145145
namespace details {

include/skyr/core/parse_query.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
namespace skyr {
1616
///
1717
struct query_parameter {
18-
std::string name;
19-
std::optional<std::string> value;
18+
std::string name{};
19+
std::optional<std::string> value{};
2020

2121
/// Constructor
2222
query_parameter() = default;

include/skyr/core/schemes.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@
1313
namespace skyr {
1414
/// \param scheme
1515
/// \returns
16-
constexpr inline auto is_special(std::string_view scheme) noexcept -> bool {
16+
constexpr auto is_special(std::string_view scheme) noexcept -> bool {
1717
return (scheme == "file") || (scheme == "ftp") || (scheme == "http") || (scheme == "https") || (scheme == "ws") ||
1818
(scheme == "wss");
1919
}
2020

2121
/// \param scheme
2222
/// \returns
23-
constexpr inline auto default_port(std::string_view scheme) noexcept -> std::optional<std::uint16_t> {
23+
constexpr auto default_port(std::string_view scheme) noexcept -> std::optional<std::uint16_t> {
2424
if (scheme == "ftp") {
25-
return 21;
25+
return 21; // NOLINT(cppcoreguidelines-avoid-magic-numbers)
2626
} else if ((scheme == "http") || (scheme == "ws")) {
27-
return 80;
27+
return 80; // NOLINT(cppcoreguidelines-avoid-magic-numbers)
2828
} else if ((scheme == "https") || (scheme == "wss")) {
29-
return 443;
29+
return 443; // NOLINT(cppcoreguidelines-avoid-magic-numbers)
3030
}
3131
return std::nullopt;
3232
}

0 commit comments

Comments
 (0)