Skip to content

Commit 65911af

Browse files
authored
Merge pull request #287 from dalle/fix-clang-warning-unused-function
* Fix clang warning unused function * `east const` formatting
2 parents 54782eb + 1a15c66 commit 65911af

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+242
-244
lines changed

README.md

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,22 @@ floating-point numbers with a C++17-like syntax (the library itself only
1616
requires C++11):
1717

1818
```C++
19-
from_chars_result from_chars(const char* first, const char* last, float& value, ...);
20-
from_chars_result from_chars(const char* first, const char* last, double& value, ...);
19+
from_chars_result from_chars(char const *first, char const *last, float &value, ...);
20+
from_chars_result from_chars(char const *first, char const *last, double &value, ...);
2121
```
2222
2323
You can also parse integer types:
2424
2525
```C++
26-
from_chars_result from_chars(const char* first, const char* last, int& value, ...);
27-
from_chars_result from_chars(const char* first, const char* last, unsigned& value, ...);
26+
from_chars_result from_chars(char const *first, char const *last, int &value, ...);
27+
from_chars_result from_chars(char const *first, char const *last, unsigned &value, ...);
2828
```
2929

3030
The return type (`from_chars_result`) is defined as the struct:
3131

3232
```C++
3333
struct from_chars_result {
34-
const char* ptr;
34+
char const *ptr;
3535
std::errc ec;
3636
};
3737
```
@@ -60,7 +60,7 @@ Example:
6060
#include <iostream>
6161
6262
int main() {
63-
const std::string input = "3.1416 xyz ";
63+
std::string input = "3.1416 xyz ";
6464
double result;
6565
auto answer = fast_float::from_chars(input.data(), input.data() + input.size(), result);
6666
if (answer.ec != std::errc()) { std::cerr << "parsing failure\n"; return EXIT_FAILURE; }
@@ -72,7 +72,7 @@ int main() {
7272
You can parse delimited numbers:
7373

7474
```C++
75-
const std::string input = "234532.3426362,7869234.9823,324562.645";
75+
std::string input = "234532.3426362,7869234.9823,324562.645";
7676
double result;
7777
auto answer = fast_float::from_chars(input.data(), input.data() + input.size(), result);
7878
if (answer.ec != std::errc()) {
@@ -143,26 +143,26 @@ following code will print the number 22250738585072012 three times:
143143
144144
int main() {
145145
uint64_t i;
146-
const char str[] = "22250738585072012";
147-
auto answer = fast_float::from_chars(str, str + strlen(str), i);
146+
std::string str = "22250738585072012";
147+
auto answer = fast_float::from_chars(str.data(), str.data() + str.size(), i);
148148
if (answer.ec != std::errc()) {
149149
std::cerr << "parsing failure\n";
150150
return EXIT_FAILURE;
151151
}
152152
std::cout << "parsed the number "<< i << std::endl;
153153
154-
const char binstr[] = "1001111000011001110110111001001010110100111000110001100";
154+
std::string binstr = "1001111000011001110110111001001010110100111000110001100";
155155
156-
answer = fast_float::from_chars(binstr, binstr + strlen(binstr), i, 2);
156+
answer = fast_float::from_chars(binstr.data(), binstr.data() + binstr.size(), i, 2);
157157
if (answer.ec != std::errc()) {
158158
std::cerr << "parsing failure\n";
159159
return EXIT_FAILURE;
160160
}
161161
std::cout << "parsed the number "<< i << std::endl;
162162
163-
const char hexstr[] = "4f0cedc95a718c";
163+
std::string hexstr = "4f0cedc95a718c";
164164
165-
answer = fast_float::from_chars(hexstr, hexstr + strlen(hexstr), i, 16);
165+
answer = fast_float::from_chars(hexstr.data(), hexstr.data() + hexstr.size(), i, 16);
166166
if (answer.ec != std::errc()) {
167167
std::cerr << "parsing failure\n";
168168
return EXIT_FAILURE;
@@ -259,7 +259,7 @@ following example:
259259
#include <iostream>
260260

261261
int main() {
262-
const std::u16string input = u"3.1416 xyz ";
262+
std::u16string input = u"3.1416 xyz ";
263263
double result;
264264
auto answer = fast_float::from_chars(input.data(), input.data() + input.size(), result);
265265
if (answer.ec != std::errc()) { std::cerr << "parsing failure\n"; return EXIT_FAILURE; }
@@ -282,7 +282,7 @@ separator (e.g., the comma). You may use it as follows.
282282
#include <iostream>
283283

284284
int main() {
285-
const std::string input = "3,1416 xyz ";
285+
std::string input = "3,1416 xyz ";
286286
double result;
287287
fast_float::parse_options options{fast_float::chars_format::general, ','};
288288
auto answer = fast_float::from_chars_advanced(input.data(), input.data() + input.size(), result, options);
@@ -299,9 +299,9 @@ int main() {
299299
#include <iostream>
300300

301301
int main() {
302-
const std::string input = "1d+4";
302+
std::string input = "1d+4";
303303
double result;
304-
fast_float::parse_options options{ fast_float::chars_format::fortran };
304+
fast_float::parse_options options{fast_float::chars_format::fortran};
305305
auto answer = fast_float::from_chars_advanced(input.data(), input.data() + input.size(), result, options);
306306
if ((answer.ec != std::errc()) || ((result != 10000))) { std::cerr << "parsing failure\n"; return EXIT_FAILURE; }
307307
std::cout << "parsed the number " << result << std::endl;
@@ -316,9 +316,9 @@ int main() {
316316
#include <iostream>
317317

318318
int main() {
319-
const std::string input = "+.1"; // not valid
319+
std::string input = "+.1"; // not valid
320320
double result;
321-
fast_float::parse_options options{ fast_float::chars_format::json };
321+
fast_float::parse_options options{fast_float::chars_format::json};
322322
auto answer = fast_float::from_chars_advanced(input.data(), input.data() + input.size(), result, options);
323323
if (answer.ec == std::errc()) { std::cerr << "should have failed\n"; return EXIT_FAILURE; }
324324
return EXIT_SUCCESS;
@@ -332,9 +332,9 @@ By default the JSON format does not allow `inf`:
332332
#include <iostream>
333333

334334
int main() {
335-
const std::string input = "inf"; // not valid in JSON
335+
std::string input = "inf"; // not valid in JSON
336336
double result;
337-
fast_float::parse_options options{ fast_float::chars_format::json };
337+
fast_float::parse_options options{fast_float::chars_format::json};
338338
auto answer = fast_float::from_chars_advanced(input.data(), input.data() + input.size(), result, options);
339339
if (answer.ec == std::errc()) { std::cerr << "should have failed\n"; return EXIT_FAILURE; }
340340
return EXIT_SUCCESS;
@@ -348,9 +348,9 @@ You can allow it with a non-standard `json_or_infnan` variant:
348348
#include <iostream>
349349

350350
int main() {
351-
const std::string input = "inf"; // not valid in JSON but we allow it with json_or_infnan
351+
std::string input = "inf"; // not valid in JSON but we allow it with json_or_infnan
352352
double result;
353-
fast_float::parse_options options{ fast_float::chars_format::json_or_infnan };
353+
fast_float::parse_options options{fast_float::chars_format::json_or_infnan};
354354
auto answer = fast_float::from_chars_advanced(input.data(), input.data() + input.size(), result, options);
355355
if (answer.ec != std::errc() || (!std::isinf(result))) { std::cerr << "should have parsed infinity\n"; return EXIT_FAILURE; }
356356
return EXIT_SUCCESS;

fuzz/from_chars.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fast_float::chars_format arbitrary_format(FuzzedDataProvider &fdp) {
1919
return chars_format::general;
2020
}
2121

22-
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
22+
extern "C" int LLVMFuzzerTestOneInput(uint8_t const *data, size_t size) {
2323
FuzzedDataProvider fdp(data, size);
2424
fast_float::chars_format format = arbitrary_format(fdp);
2525
double result_d = 0.0;

include/fast_float/ascii_number.h

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ fastfloat_really_inline constexpr uint64_t byteswap(uint64_t val) {
4545
// Read 8 UC into a u64. Truncates UC if not char.
4646
template <typename UC>
4747
fastfloat_really_inline FASTFLOAT_CONSTEXPR20 uint64_t
48-
read8_to_u64(const UC *chars) {
48+
read8_to_u64(UC const *chars) {
4949
if (cpp20_and_in_constexpr() || !std::is_same<UC, char>::value) {
5050
uint64_t val = 0;
5151
for (int i = 0; i < 8; ++i) {
@@ -65,9 +65,9 @@ read8_to_u64(const UC *chars) {
6565

6666
#ifdef FASTFLOAT_SSE2
6767

68-
fastfloat_really_inline uint64_t simd_read8_to_u64(const __m128i data) {
68+
fastfloat_really_inline uint64_t simd_read8_to_u64(__m128i const data) {
6969
FASTFLOAT_SIMD_DISABLE_WARNINGS
70-
const __m128i packed = _mm_packus_epi16(data, data);
70+
__m128i const packed = _mm_packus_epi16(data, data);
7171
#ifdef FASTFLOAT_64BIT
7272
return uint64_t(_mm_cvtsi128_si64(packed));
7373
#else
@@ -79,26 +79,26 @@ fastfloat_really_inline uint64_t simd_read8_to_u64(const __m128i data) {
7979
FASTFLOAT_SIMD_RESTORE_WARNINGS
8080
}
8181

82-
fastfloat_really_inline uint64_t simd_read8_to_u64(const char16_t *chars) {
82+
fastfloat_really_inline uint64_t simd_read8_to_u64(char16_t const *chars) {
8383
FASTFLOAT_SIMD_DISABLE_WARNINGS
8484
return simd_read8_to_u64(
85-
_mm_loadu_si128(reinterpret_cast<const __m128i *>(chars)));
85+
_mm_loadu_si128(reinterpret_cast<__m128i const *>(chars)));
8686
FASTFLOAT_SIMD_RESTORE_WARNINGS
8787
}
8888

8989
#elif defined(FASTFLOAT_NEON)
9090

91-
fastfloat_really_inline uint64_t simd_read8_to_u64(const uint16x8_t data) {
91+
fastfloat_really_inline uint64_t simd_read8_to_u64(uint16x8_t const data) {
9292
FASTFLOAT_SIMD_DISABLE_WARNINGS
9393
uint8x8_t utf8_packed = vmovn_u16(data);
9494
return vget_lane_u64(vreinterpret_u64_u8(utf8_packed), 0);
9595
FASTFLOAT_SIMD_RESTORE_WARNINGS
9696
}
9797

98-
fastfloat_really_inline uint64_t simd_read8_to_u64(const char16_t *chars) {
98+
fastfloat_really_inline uint64_t simd_read8_to_u64(char16_t const *chars) {
9999
FASTFLOAT_SIMD_DISABLE_WARNINGS
100100
return simd_read8_to_u64(
101-
vld1q_u16(reinterpret_cast<const uint16_t *>(chars)));
101+
vld1q_u16(reinterpret_cast<uint16_t const *>(chars)));
102102
FASTFLOAT_SIMD_RESTORE_WARNINGS
103103
}
104104

@@ -118,9 +118,9 @@ uint64_t simd_read8_to_u64(UC const *) {
118118
// credit @aqrit
119119
fastfloat_really_inline FASTFLOAT_CONSTEXPR14 uint32_t
120120
parse_eight_digits_unrolled(uint64_t val) {
121-
const uint64_t mask = 0x000000FF000000FF;
122-
const uint64_t mul1 = 0x000F424000000064; // 100 + (1000000ULL << 32)
123-
const uint64_t mul2 = 0x0000271000000001; // 1 + (10000ULL << 32)
121+
uint64_t const mask = 0x000000FF000000FF;
122+
uint64_t const mul1 = 0x000F424000000064; // 100 + (1000000ULL << 32)
123+
uint64_t const mul2 = 0x0000271000000001; // 1 + (10000ULL << 32)
124124
val -= 0x3030303030303030;
125125
val = (val * 10) + (val >> 8); // val = (val * 2561) >> 8;
126126
val = (((val & mask) * mul1) + (((val >> 16) & mask) * mul2)) >> 32;
@@ -150,20 +150,20 @@ is_made_of_eight_digits_fast(uint64_t val) noexcept {
150150
// Using this style (instead of is_made_of_eight_digits_fast() then
151151
// parse_eight_digits_unrolled()) ensures we don't load SIMD registers twice.
152152
fastfloat_really_inline FASTFLOAT_CONSTEXPR20 bool
153-
simd_parse_if_eight_digits_unrolled(const char16_t *chars,
153+
simd_parse_if_eight_digits_unrolled(char16_t const *chars,
154154
uint64_t &i) noexcept {
155155
if (cpp20_and_in_constexpr()) {
156156
return false;
157157
}
158158
#ifdef FASTFLOAT_SSE2
159159
FASTFLOAT_SIMD_DISABLE_WARNINGS
160-
const __m128i data =
161-
_mm_loadu_si128(reinterpret_cast<const __m128i *>(chars));
160+
__m128i const data =
161+
_mm_loadu_si128(reinterpret_cast<__m128i const *>(chars));
162162

163163
// (x - '0') <= 9
164164
// http://0x80.pl/articles/simd-parsing-int-sequences.html
165-
const __m128i t0 = _mm_add_epi16(data, _mm_set1_epi16(32720));
166-
const __m128i t1 = _mm_cmpgt_epi16(t0, _mm_set1_epi16(-32759));
165+
__m128i const t0 = _mm_add_epi16(data, _mm_set1_epi16(32720));
166+
__m128i const t1 = _mm_cmpgt_epi16(t0, _mm_set1_epi16(-32759));
167167

168168
if (_mm_movemask_epi8(t1) == 0) {
169169
i = i * 100000000 + parse_eight_digits_unrolled(simd_read8_to_u64(data));
@@ -173,12 +173,12 @@ simd_parse_if_eight_digits_unrolled(const char16_t *chars,
173173
FASTFLOAT_SIMD_RESTORE_WARNINGS
174174
#elif defined(FASTFLOAT_NEON)
175175
FASTFLOAT_SIMD_DISABLE_WARNINGS
176-
const uint16x8_t data = vld1q_u16(reinterpret_cast<const uint16_t *>(chars));
176+
uint16x8_t const data = vld1q_u16(reinterpret_cast<uint16_t const *>(chars));
177177

178178
// (x - '0') <= 9
179179
// http://0x80.pl/articles/simd-parsing-int-sequences.html
180-
const uint16x8_t t0 = vsubq_u16(data, vmovq_n_u16('0'));
181-
const uint16x8_t mask = vcltq_u16(t0, vmovq_n_u16('9' - '0' + 1));
180+
uint16x8_t const t0 = vsubq_u16(data, vmovq_n_u16('0'));
181+
uint16x8_t const mask = vcltq_u16(t0, vmovq_n_u16('9' - '0' + 1));
182182

183183
if (vminvq_u16(mask) == 0xFFFF) {
184184
i = i * 100000000 + parse_eight_digits_unrolled(simd_read8_to_u64(data));
@@ -208,7 +208,7 @@ bool simd_parse_if_eight_digits_unrolled(UC const *, uint64_t &) {
208208

209209
template <typename UC, FASTFLOAT_ENABLE_IF(!std::is_same<UC, char>::value) = 0>
210210
fastfloat_really_inline FASTFLOAT_CONSTEXPR20 void
211-
loop_parse_if_eight_digits(const UC *&p, const UC *const pend, uint64_t &i) {
211+
loop_parse_if_eight_digits(UC const *&p, UC const *const pend, uint64_t &i) {
212212
if (!has_simd_opt<UC>()) {
213213
return;
214214
}
@@ -220,7 +220,7 @@ loop_parse_if_eight_digits(const UC *&p, const UC *const pend, uint64_t &i) {
220220
}
221221

222222
fastfloat_really_inline FASTFLOAT_CONSTEXPR20 void
223-
loop_parse_if_eight_digits(const char *&p, const char *const pend,
223+
loop_parse_if_eight_digits(char const *&p, char const *const pend,
224224
uint64_t &i) {
225225
// optimizes better than parse_if_eight_digits_unrolled() for UC = char.
226226
while ((std::distance(p, pend) >= 8) &&
@@ -259,12 +259,12 @@ template <typename UC> struct parsed_number_string_t {
259259
bool valid{false};
260260
bool too_many_digits{false};
261261
// contains the range of the significant digits
262-
span<const UC> integer{}; // non-nullable
263-
span<const UC> fraction{}; // nullable
262+
span<UC const> integer{}; // non-nullable
263+
span<UC const> fraction{}; // nullable
264264
parse_error error{parse_error::no_error};
265265
};
266266

267-
using byte_span = span<const char>;
267+
using byte_span = span<char const>;
268268
using parsed_number_string = parsed_number_string_t<char>;
269269

270270
template <typename UC>
@@ -328,7 +328,7 @@ parse_number_string(UC const *p, UC const *pend,
328328
}
329329
UC const *const end_of_integer_part = p;
330330
int64_t digit_count = int64_t(end_of_integer_part - start_digits);
331-
answer.integer = span<const UC>(start_digits, size_t(digit_count));
331+
answer.integer = span<UC const>(start_digits, size_t(digit_count));
332332
if (uint64_t(fmt & detail::basic_json_fmt)) {
333333
// at least 1 digit in integer part, without leading zeros
334334
if (digit_count == 0) {
@@ -341,7 +341,7 @@ parse_number_string(UC const *p, UC const *pend,
341341
}
342342

343343
int64_t exponent = 0;
344-
const bool has_decimal_point = (p != pend) && (*p == decimal_point);
344+
bool const has_decimal_point = (p != pend) && (*p == decimal_point);
345345
if (has_decimal_point) {
346346
++p;
347347
UC const *before = p;
@@ -355,7 +355,7 @@ parse_number_string(UC const *p, UC const *pend,
355355
i = i * 10 + digit; // in rare cases, this will overflow, but that's ok
356356
}
357357
exponent = before - p;
358-
answer.fraction = span<const UC>(before, size_t(p - before));
358+
answer.fraction = span<UC const>(before, size_t(p - before));
359359
digit_count -= exponent;
360360
}
361361
if (uint64_t(fmt & detail::basic_json_fmt)) {
@@ -446,7 +446,7 @@ parse_number_string(UC const *p, UC const *pend,
446446
i = 0;
447447
p = answer.integer.ptr;
448448
UC const *int_end = p + answer.integer.len();
449-
const uint64_t minimal_nineteen_digit_integer{1000000000000000000};
449+
uint64_t const minimal_nineteen_digit_integer{1000000000000000000};
450450
while ((i < minimal_nineteen_digit_integer) && (p != int_end)) {
451451
i = i * 10 + uint64_t(*p - UC('0'));
452452
++p;
@@ -498,7 +498,7 @@ parse_int_string(UC const *p, UC const *pend, T &value,
498498
++p;
499499
}
500500

501-
const bool has_leading_zeros = p > start_num;
501+
bool const has_leading_zeros = p > start_num;
502502

503503
UC const *const start_digits = p;
504504

include/fast_float/bigint.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ template <uint16_t size> struct stackvec {
4343
uint16_t length{0};
4444

4545
stackvec() = default;
46-
stackvec(const stackvec &) = delete;
47-
stackvec &operator=(const stackvec &) = delete;
46+
stackvec(stackvec const &) = delete;
47+
stackvec &operator=(stackvec const &) = delete;
4848
stackvec(stackvec &&) = delete;
4949
stackvec &operator=(stackvec &&other) = delete;
5050

@@ -423,8 +423,8 @@ struct bigint : pow5_tables<> {
423423
stackvec<bigint_limbs> vec;
424424

425425
FASTFLOAT_CONSTEXPR20 bigint() : vec() {}
426-
bigint(const bigint &) = delete;
427-
bigint &operator=(const bigint &) = delete;
426+
bigint(bigint const &) = delete;
427+
bigint &operator=(bigint const &) = delete;
428428
bigint(bigint &&) = delete;
429429
bigint &operator=(bigint &&other) = delete;
430430

@@ -473,7 +473,7 @@ struct bigint : pow5_tables<> {
473473
// positive, this is larger, otherwise they are equal.
474474
// the limbs are stored in little-endian order, so we
475475
// must compare the limbs in ever order.
476-
FASTFLOAT_CONSTEXPR20 int compare(const bigint &other) const noexcept {
476+
FASTFLOAT_CONSTEXPR20 int compare(bigint const &other) const noexcept {
477477
if (vec.len() > other.vec.len()) {
478478
return 1;
479479
} else if (vec.len() < other.vec.len()) {
@@ -527,7 +527,7 @@ struct bigint : pow5_tables<> {
527527
} else if (!vec.is_empty()) {
528528
// move limbs
529529
limb *dst = vec.data + n;
530-
const limb *src = vec.data;
530+
limb const *src = vec.data;
531531
std::copy_backward(src, src + vec.len(), dst + vec.len());
532532
// fill in empty limbs
533533
limb *first = vec.data;

include/fast_float/decimal_to_binary.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace fast_float {
2020
template <int bit_precision>
2121
fastfloat_really_inline FASTFLOAT_CONSTEXPR20 value128
2222
compute_product_approximation(int64_t q, uint64_t w) {
23-
const int index = 2 * int(q - powers::smallest_power_of_five);
23+
int const index = 2 * int(q - powers::smallest_power_of_five);
2424
// For small values of q, e.g., q in [0,27], the answer is always exact
2525
// because The line value128 firstproduct = full_multiplication(w,
2626
// power_of_five_128[index]); gives the exact answer.

0 commit comments

Comments
 (0)