Skip to content

Commit 6995689

Browse files
author
Hana Dusíková
committed
fix #218 fixing warnings in clang for implicit conversions
1 parent 0301cf5 commit 6995689

File tree

8 files changed

+19
-37
lines changed

8 files changed

+19
-37
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ DESATOMAT := /bin/false
99

1010
CXX_STANDARD := 20
1111

12-
override CXXFLAGS := $(CXXFLAGS) -std=c++$(CXX_STANDARD) -Iinclude -O3 -pedantic -Wall -Wextra -Werror
12+
override CXXFLAGS := $(CXXFLAGS) -std=c++$(CXX_STANDARD) -Iinclude -O3 -pedantic -Wall -Wextra -Werror -Wconversion
1313
LDFLAGS :=
1414

1515
TESTS := $(wildcard tests/*.cpp) $(wildcard tests/benchmark/*.cpp)

include/ctll/fixed_string.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ template <size_t N> struct fixed_string {
132132
real_size = out;
133133
} else if constexpr (std::is_same_v<T, wchar_t> || std::is_same_v<T, char32_t>) {
134134
for (size_t i{0}; i < N; ++i) {
135-
content[i] = input[i];
135+
content[i] = static_cast<char32_t>(input[i]);
136136
if ((i == (N-1)) && (input[i] == 0)) break;
137137
real_size++;
138138
}

include/ctre/atoms_unicode.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ template <auto Name, auto Value> struct property;
2424
// unicode TS#18 level 1.2 general_category
2525
template <uni::detail::binary_prop Property> struct binary_property<Property> {
2626
template <typename CharT> inline static constexpr bool match_char(CharT c) noexcept {
27-
return uni::detail::get_binary_prop<Property>(c);
27+
return uni::detail::get_binary_prop<Property>(static_cast<char32_t>(c));
2828
}
2929
};
3030

include/ctre/utf8.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ struct utf8_iterator {
145145
// remove utf8 front bits, get only significant part
146146
// and add first trailing unit
147147

148-
char32_t result = ((ptr[0] & mask) << 6) | (ptr[1] & 0b0011'1111u);
148+
char32_t result = static_cast<char32_t>((ptr[0] & mask) << 6u) | (ptr[1] & 0b0011'1111u);
149149

150150
// add rest of trailing units
151151
if (length == 1) CTRE_LIKELY {

include/unicode-db/unicode-db.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ struct bool_trie {
266266
}
267267
}
268268

269-
std::size_t i5 = (child << 6) + ((c >> 6) & 0x3f);
269+
std::size_t i5 = static_cast<std::size_t>(child << 6) + ((c >> 6) & 0x3f);
270270
auto leaf = 0;
271271
if constexpr(r5_s > 0) {
272272
if(i5 >= r5_t_f && i5 < r5_t_f + r5_s) {
@@ -377,7 +377,7 @@ struct string_with_idx { const char* name; uint32_t value; };
377377
namespace uni {
378378

379379
constexpr double numeric_value::value() const {
380-
return numerator() / double(_d);
380+
return static_cast<double>(numerator()) / static_cast<double>(_d);
381381
}
382382

383383
constexpr long long numeric_value::numerator() const {
@@ -7332,7 +7332,7 @@ constexpr numeric_value cp_numeric_value(char32_t cp) {
73327332
}())) {
73337333
return {};
73347334
}
7335-
uint16_t d = 1;
7335+
int16_t d = 1;
73367336
detail::get_numeric_value(cp, detail::tables::numeric_data_d, d);
73377337
return numeric_value(res, d);
73387338
}

single-header/ctre-unicode.hpp

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,6 @@ Software.
240240
#include <cstddef>
241241
#include <string_view>
242242
#include <cstdint>
243-
#include <memory>
244243

245244
namespace ctll {
246245

@@ -368,7 +367,7 @@ template <size_t N> struct fixed_string {
368367
real_size = out;
369368
} else if constexpr (std::is_same_v<T, wchar_t> || std::is_same_v<T, char32_t>) {
370369
for (size_t i{0}; i < N; ++i) {
371-
content[i] = input[i];
370+
content[i] = static_cast<char32_t>(input[i]);
372371
if ((i == (N-1)) && (input[i] == 0)) break;
373372
real_size++;
374373
}
@@ -1670,7 +1669,7 @@ template <auto Name, auto Value> struct property;
16701669
// unicode TS#18 level 1.2 general_category
16711670
template <uni::detail::binary_prop Property> struct binary_property<Property> {
16721671
template <typename CharT> inline static constexpr bool match_char(CharT c) noexcept {
1673-
return uni::detail::get_binary_prop<Property>(c);
1672+
return uni::detail::get_binary_prop<Property>(static_cast<char32_t>(c));
16741673
}
16751674
};
16761675

@@ -2870,7 +2869,7 @@ struct utf8_iterator {
28702869
// remove utf8 front bits, get only significant part
28712870
// and add first trailing unit
28722871

2873-
char32_t result = ((ptr[0] & mask) << 6) | (ptr[1] & 0b0011'1111u);
2872+
char32_t result = static_cast<char32_t>((ptr[0] & mask) << 6u) | (ptr[1] & 0b0011'1111u);
28742873

28752874
// add rest of trailing units
28762875
if (length == 1) CTRE_LIKELY {
@@ -2979,19 +2978,11 @@ template <size_t Id, typename Name = void> struct captured_content {
29792978
if constexpr (std::is_same_v<Iterator, utf8_iterator>) {
29802979
return _begin.ptr;
29812980
} else {
2982-
#if __cpp_lib_to_address >= 201711L
2983-
return std::to_address(_begin);
2984-
#else
29852981
return &*_begin;
2986-
#endif
29872982
}
29882983
#else
2989-
#if __cpp_lib_to_address >= 201711L
2990-
return std::to_address(_begin);
2991-
#else
29922984
return &*_begin;
29932985
#endif
2994-
#endif
29952986
}
29962987

29972988
constexpr CTRE_FORCE_INLINE const auto * data() const noexcept {
@@ -5588,7 +5579,7 @@ struct bool_trie {
55885579
}
55895580
}
55905581

5591-
std::size_t i5 = (child << 6) + ((c >> 6) & 0x3f);
5582+
std::size_t i5 = static_cast<std::size_t>(child << 6) + ((c >> 6) & 0x3f);
55925583
auto leaf = 0;
55935584
if constexpr(r5_s > 0) {
55945585
if(i5 >= r5_t_f && i5 < r5_t_f + r5_s) {
@@ -5696,7 +5687,7 @@ struct string_with_idx { const char* name; uint32_t value; };
56965687
namespace uni {
56975688

56985689
constexpr double numeric_value::value() const {
5699-
return numerator() / double(_d);
5690+
return static_cast<double>(numerator()) / static_cast<double>(_d);
57005691
}
57015692

57025693
constexpr long long numeric_value::numerator() const {
@@ -12648,7 +12639,7 @@ constexpr numeric_value cp_numeric_value(char32_t cp) {
1264812639
}())) {
1264912640
return {};
1265012641
}
12651-
uint16_t d = 1;
12642+
int16_t d = 1;
1265212643
detail::get_numeric_value(cp, detail::tables::numeric_data_d, d);
1265312644
return numeric_value(res, d);
1265412645
}

single-header/ctre.hpp

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,6 @@ Software.
237237
#include <cstddef>
238238
#include <string_view>
239239
#include <cstdint>
240-
#include <memory>
241240

242241
namespace ctll {
243242

@@ -365,7 +364,7 @@ template <size_t N> struct fixed_string {
365364
real_size = out;
366365
} else if constexpr (std::is_same_v<T, wchar_t> || std::is_same_v<T, char32_t>) {
367366
for (size_t i{0}; i < N; ++i) {
368-
content[i] = input[i];
367+
content[i] = static_cast<char32_t>(input[i]);
369368
if ((i == (N-1)) && (input[i] == 0)) break;
370369
real_size++;
371370
}
@@ -1667,7 +1666,7 @@ template <auto Name, auto Value> struct property;
16671666
// unicode TS#18 level 1.2 general_category
16681667
template <uni::detail::binary_prop Property> struct binary_property<Property> {
16691668
template <typename CharT> inline static constexpr bool match_char(CharT c) noexcept {
1670-
return uni::detail::get_binary_prop<Property>(c);
1669+
return uni::detail::get_binary_prop<Property>(static_cast<char32_t>(c));
16711670
}
16721671
};
16731672

@@ -2867,7 +2866,7 @@ struct utf8_iterator {
28672866
// remove utf8 front bits, get only significant part
28682867
// and add first trailing unit
28692868

2870-
char32_t result = ((ptr[0] & mask) << 6) | (ptr[1] & 0b0011'1111u);
2869+
char32_t result = static_cast<char32_t>((ptr[0] & mask) << 6u) | (ptr[1] & 0b0011'1111u);
28712870

28722871
// add rest of trailing units
28732872
if (length == 1) CTRE_LIKELY {
@@ -2976,19 +2975,11 @@ template <size_t Id, typename Name = void> struct captured_content {
29762975
if constexpr (std::is_same_v<Iterator, utf8_iterator>) {
29772976
return _begin.ptr;
29782977
} else {
2979-
#if __cpp_lib_to_address >= 201711L
2980-
return std::to_address(_begin);
2981-
#else
29822978
return &*_begin;
2983-
#endif
29842979
}
29852980
#else
2986-
#if __cpp_lib_to_address >= 201711L
2987-
return std::to_address(_begin);
2988-
#else
29892981
return &*_begin;
29902982
#endif
2991-
#endif
29922983
}
29932984

29942985
constexpr CTRE_FORCE_INLINE const auto * data() const noexcept {

single-header/unicode-db.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ struct bool_trie {
266266
}
267267
}
268268

269-
std::size_t i5 = (child << 6) + ((c >> 6) & 0x3f);
269+
std::size_t i5 = static_cast<std::size_t>(child << 6) + ((c >> 6) & 0x3f);
270270
auto leaf = 0;
271271
if constexpr(r5_s > 0) {
272272
if(i5 >= r5_t_f && i5 < r5_t_f + r5_s) {
@@ -377,7 +377,7 @@ struct string_with_idx { const char* name; uint32_t value; };
377377
namespace uni {
378378

379379
constexpr double numeric_value::value() const {
380-
return numerator() / double(_d);
380+
return static_cast<double>(numerator()) / static_cast<double>(_d);
381381
}
382382

383383
constexpr long long numeric_value::numerator() const {
@@ -7332,7 +7332,7 @@ constexpr numeric_value cp_numeric_value(char32_t cp) {
73327332
}())) {
73337333
return {};
73347334
}
7335-
uint16_t d = 1;
7335+
int16_t d = 1;
73367336
detail::get_numeric_value(cp, detail::tables::numeric_data_d, d);
73377337
return numeric_value(res, d);
73387338
}

0 commit comments

Comments
 (0)