Skip to content

Commit

Permalink
Fix somehow shadowed clang-tidy warnings (#418)
Browse files Browse the repository at this point in the history
* fixed clang-tidy(14.0.0) warnings somehow shadowed in using 18.1.3

* [bot] run clang-format & amalgamation
  • Loading branch information
fktn-k authored Oct 27, 2024
1 parent b18b27a commit 9f704b0
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 30 deletions.
2 changes: 2 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Checks: '*,
-google-readability-todo,
-hicpp-avoid-c-arrays,
-hicpp-explicit-conversions,
-hicpp-noexcept-move,
-hicpp-signed-bitwise,
-hicpp-uppercase-literal-suffix,
-hicpp-vararg,
Expand All @@ -32,6 +33,7 @@ Checks: '*,
-modernize-use-nodiscard,
-modernize-type-traits,
-modernize-use-trailing-return-type,
-performance-noexcept-move-constructor,
-readability-function-cognitive-complexity,
-readability-identifier-length,
-readability-implicit-bool-conversion,
Expand Down
18 changes: 9 additions & 9 deletions include/fkYAML/detail/conversions/scalar_conv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ inline bool atoi_dec_unchecked(const char* p_begin, const char* p_end, IntType&
return false;
}
// Overflow is intentional when the IntType is signed.
i = i * IntType(10) + IntType(c - '0');
i = i * static_cast<IntType>(10) + static_cast<IntType>(c - '0');
} while (++p_begin != p_end);

return true;
Expand Down Expand Up @@ -569,7 +569,7 @@ inline bool atoi_oct(const char* p_begin, const char* p_end, IntType& i) noexcep
if FK_YAML_UNLIKELY (c < '0' || '7' < c) {
return false;
}
i = i * IntType(8) + IntType(c - '0');
i = i * static_cast<IntType>(8) + static_cast<IntType>(c - '0');
} while (++p_begin != p_end);

return true;
Expand Down Expand Up @@ -608,18 +608,18 @@ inline bool atoi_hex(const char* p_begin, const char* p_end, IntType& i) noexcep
const char c = *p_begin;
IntType ci = 0;
if ('0' <= c && c <= '9') {
ci = IntType(c - '0');
ci = static_cast<IntType>(c - '0');
}
else if ('A' <= c && c <= 'F') {
ci = IntType(c - 'A' + 10);
ci = static_cast<IntType>(c - 'A' + 10);
}
else if ('a' <= c && c <= 'f') {
ci = IntType(c - 'a' + 10);
ci = static_cast<IntType>(c - 'a' + 10);
}
else {
return false;
}
i = i * IntType(16) + ci;
i = i * static_cast<IntType>(16) + ci;
// NOLINTEND(bugprone-misplaced-widening-cast)
} while (++p_begin != p_end);

Expand Down Expand Up @@ -662,7 +662,7 @@ inline bool atoi(CharItr begin, CharItr end, IntType& i) noexcept {

const bool success = atoi_dec_neg(p_begin + 1, p_end, i);
if (success) {
i *= IntType(-1);
i *= static_cast<IntType>(-1);
}

return success;
Expand Down Expand Up @@ -790,7 +790,7 @@ inline bool atof(CharItr begin, CharItr end, FloatType& f) noexcept(noexcept(ato
(std::strncmp(p_from_second, ".Inf", 4) == 0) ||
(std::strncmp(p_from_second, ".INF", 4) == 0);
if (is_inf) {
set_infinity(f, *p_begin == '-' ? FloatType(-1.) : FloatType(1.));
set_infinity(f, *p_begin == '-' ? static_cast<FloatType>(-1.) : static_cast<FloatType>(1.));
return true;
}
}
Expand All @@ -804,7 +804,7 @@ inline bool atof(CharItr begin, CharItr end, FloatType& f) noexcept(noexcept(ato
const bool is_inf = (std::strncmp(p_begin, ".inf", 4) == 0) || (std::strncmp(p_begin, ".Inf", 4) == 0) ||
(std::strncmp(p_begin, ".INF", 4) == 0);
if (is_inf) {
set_infinity(f, FloatType(1.));
set_infinity(f, static_cast<FloatType>(1.));
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion include/fkYAML/detail/encodings/utf_encode_detector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ struct utf_encode_detector<ItrType, enable_if_t<is_iterator_of<ItrType, char>::v
std::array<uint8_t, 4> bytes {};
bytes.fill(0xFFu);
for (int i = 0; i < 4 && begin + i != end; i++) {
bytes[i] = uint8_t(begin[i]); // NOLINT(cppcoreguidelines-pro-bounds-constant-array-index)
bytes[i] = static_cast<uint8_t>(begin[i]); // NOLINT(cppcoreguidelines-pro-bounds-constant-array-index)
}

bool has_bom = false;
Expand Down
14 changes: 9 additions & 5 deletions include/fkYAML/detail/input/input_adapter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,16 @@ class iterator_input_adapter<IterType, enable_if_t<is_iterator_of<IterType, char

switch (num_bytes) {
case 2: {
const std::initializer_list<uint8_t> bytes {first, uint8_t(*current++)};
const std::initializer_list<uint8_t> bytes {first, static_cast<uint8_t>(*current++)};
const bool is_valid = utf8::validate(bytes);
if FK_YAML_UNLIKELY (!is_valid) {
throw fkyaml::invalid_encoding("Invalid UTF-8 encoding.", bytes);
}
break;
}
case 3: {
const std::initializer_list<uint8_t> bytes {first, uint8_t(*current++), uint8_t(*current++)};
const std::initializer_list<uint8_t> bytes {
first, static_cast<uint8_t>(*current++), static_cast<uint8_t>(*current++)};
const bool is_valid = utf8::validate(bytes);
if FK_YAML_UNLIKELY (!is_valid) {
throw fkyaml::invalid_encoding("Invalid UTF-8 encoding.", bytes);
Expand All @@ -111,7 +112,10 @@ class iterator_input_adapter<IterType, enable_if_t<is_iterator_of<IterType, char
}
case 4: {
const std::initializer_list<uint8_t> bytes {
first, uint8_t(*current++), uint8_t(*current++), uint8_t(*current++)};
first,
static_cast<uint8_t>(*current++),
static_cast<uint8_t>(*current++),
static_cast<uint8_t>(*current++)};
const bool is_valid = utf8::validate(bytes);
if FK_YAML_UNLIKELY (!is_valid) {
throw fkyaml::invalid_encoding("Invalid UTF-8 encoding.", bytes);
Expand Down Expand Up @@ -172,8 +176,8 @@ class iterator_input_adapter<IterType, enable_if_t<is_iterator_of<IterType, char
IterType current = m_begin;
while (current != m_end || encoded_buf_size != 0) {
while (current != m_end && encoded_buf_size < 2) {
auto utf16 = static_cast<char16_t>(uint8_t(*current++) << shift_bits[0]);
utf16 |= static_cast<char16_t>(uint8_t(*current++) << shift_bits[1]);
auto utf16 = static_cast<char16_t>(static_cast<uint8_t>(*current++) << shift_bits[0]);
utf16 |= static_cast<char16_t>(static_cast<uint8_t>(*current++) << shift_bits[1]);

// skip appending CRs.
if FK_YAML_LIKELY (utf16 != char16_t(0x000Du)) {
Expand Down
34 changes: 19 additions & 15 deletions single_include/fkYAML/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4450,7 +4450,7 @@ inline bool atoi_dec_unchecked(const char* p_begin, const char* p_end, IntType&
return false;
}
// Overflow is intentional when the IntType is signed.
i = i * IntType(10) + IntType(c - '0');
i = i * static_cast<IntType>(10) + static_cast<IntType>(c - '0');
} while (++p_begin != p_end);

return true;
Expand Down Expand Up @@ -4575,7 +4575,7 @@ inline bool atoi_oct(const char* p_begin, const char* p_end, IntType& i) noexcep
if FK_YAML_UNLIKELY (c < '0' || '7' < c) {
return false;
}
i = i * IntType(8) + IntType(c - '0');
i = i * static_cast<IntType>(8) + static_cast<IntType>(c - '0');
} while (++p_begin != p_end);

return true;
Expand Down Expand Up @@ -4614,18 +4614,18 @@ inline bool atoi_hex(const char* p_begin, const char* p_end, IntType& i) noexcep
const char c = *p_begin;
IntType ci = 0;
if ('0' <= c && c <= '9') {
ci = IntType(c - '0');
ci = static_cast<IntType>(c - '0');
}
else if ('A' <= c && c <= 'F') {
ci = IntType(c - 'A' + 10);
ci = static_cast<IntType>(c - 'A' + 10);
}
else if ('a' <= c && c <= 'f') {
ci = IntType(c - 'a' + 10);
ci = static_cast<IntType>(c - 'a' + 10);
}
else {
return false;
}
i = i * IntType(16) + ci;
i = i * static_cast<IntType>(16) + ci;
// NOLINTEND(bugprone-misplaced-widening-cast)
} while (++p_begin != p_end);

Expand Down Expand Up @@ -4668,7 +4668,7 @@ inline bool atoi(CharItr begin, CharItr end, IntType& i) noexcept {

const bool success = atoi_dec_neg(p_begin + 1, p_end, i);
if (success) {
i *= IntType(-1);
i *= static_cast<IntType>(-1);
}

return success;
Expand Down Expand Up @@ -4796,7 +4796,7 @@ inline bool atof(CharItr begin, CharItr end, FloatType& f) noexcept(noexcept(ato
(std::strncmp(p_from_second, ".Inf", 4) == 0) ||
(std::strncmp(p_from_second, ".INF", 4) == 0);
if (is_inf) {
set_infinity(f, *p_begin == '-' ? FloatType(-1.) : FloatType(1.));
set_infinity(f, *p_begin == '-' ? static_cast<FloatType>(-1.) : static_cast<FloatType>(1.));
return true;
}
}
Expand All @@ -4810,7 +4810,7 @@ inline bool atof(CharItr begin, CharItr end, FloatType& f) noexcept(noexcept(ato
const bool is_inf = (std::strncmp(p_begin, ".inf", 4) == 0) || (std::strncmp(p_begin, ".Inf", 4) == 0) ||
(std::strncmp(p_begin, ".INF", 4) == 0);
if (is_inf) {
set_infinity(f, FloatType(1.));
set_infinity(f, static_cast<FloatType>(1.));
return true;
}

Expand Down Expand Up @@ -7995,7 +7995,7 @@ struct utf_encode_detector<ItrType, enable_if_t<is_iterator_of<ItrType, char>::v
std::array<uint8_t, 4> bytes {};
bytes.fill(0xFFu);
for (int i = 0; i < 4 && begin + i != end; i++) {
bytes[i] = uint8_t(begin[i]); // NOLINT(cppcoreguidelines-pro-bounds-constant-array-index)
bytes[i] = static_cast<uint8_t>(begin[i]); // NOLINT(cppcoreguidelines-pro-bounds-constant-array-index)
}

bool has_bom = false;
Expand Down Expand Up @@ -8311,15 +8311,16 @@ class iterator_input_adapter<IterType, enable_if_t<is_iterator_of<IterType, char

switch (num_bytes) {
case 2: {
const std::initializer_list<uint8_t> bytes {first, uint8_t(*current++)};
const std::initializer_list<uint8_t> bytes {first, static_cast<uint8_t>(*current++)};
const bool is_valid = utf8::validate(bytes);
if FK_YAML_UNLIKELY (!is_valid) {
throw fkyaml::invalid_encoding("Invalid UTF-8 encoding.", bytes);
}
break;
}
case 3: {
const std::initializer_list<uint8_t> bytes {first, uint8_t(*current++), uint8_t(*current++)};
const std::initializer_list<uint8_t> bytes {
first, static_cast<uint8_t>(*current++), static_cast<uint8_t>(*current++)};
const bool is_valid = utf8::validate(bytes);
if FK_YAML_UNLIKELY (!is_valid) {
throw fkyaml::invalid_encoding("Invalid UTF-8 encoding.", bytes);
Expand All @@ -8328,7 +8329,10 @@ class iterator_input_adapter<IterType, enable_if_t<is_iterator_of<IterType, char
}
case 4: {
const std::initializer_list<uint8_t> bytes {
first, uint8_t(*current++), uint8_t(*current++), uint8_t(*current++)};
first,
static_cast<uint8_t>(*current++),
static_cast<uint8_t>(*current++),
static_cast<uint8_t>(*current++)};
const bool is_valid = utf8::validate(bytes);
if FK_YAML_UNLIKELY (!is_valid) {
throw fkyaml::invalid_encoding("Invalid UTF-8 encoding.", bytes);
Expand Down Expand Up @@ -8389,8 +8393,8 @@ class iterator_input_adapter<IterType, enable_if_t<is_iterator_of<IterType, char
IterType current = m_begin;
while (current != m_end || encoded_buf_size != 0) {
while (current != m_end && encoded_buf_size < 2) {
auto utf16 = static_cast<char16_t>(uint8_t(*current++) << shift_bits[0]);
utf16 |= static_cast<char16_t>(uint8_t(*current++) << shift_bits[1]);
auto utf16 = static_cast<char16_t>(static_cast<uint8_t>(*current++) << shift_bits[0]);
utf16 |= static_cast<char16_t>(static_cast<uint8_t>(*current++) << shift_bits[1]);

// skip appending CRs.
if FK_YAML_LIKELY (utf16 != char16_t(0x000Du)) {
Expand Down

0 comments on commit 9f704b0

Please sign in to comment.