Skip to content

Commit 2787e1c

Browse files
committed
Fix some clang-tidy warnings
1 parent 1230a77 commit 2787e1c

File tree

11 files changed

+85
-45
lines changed

11 files changed

+85
-45
lines changed

include/strf/detail/facets/numpunct.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ class digits_grouping
210210
}
211211
if (it.is_last()) {
212212
return it.shall_repeat_current()
213-
? (count + (digcount - 1) / grp)
213+
? (count + (digcount - 1) / grp) // NOLINT(clang-analyzer-core.DivideZero)
214214
: count + (digcount > grp);
215215
}
216216
++count;

include/strf/detail/polymorphic_printer.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ class polymorphic_printer
1717
public:
1818
using char_type = CharT;
1919

20-
polymorphic_printer() = default;
20+
constexpr polymorphic_printer() noexcept = default;
21+
constexpr polymorphic_printer(const polymorphic_printer&) = default;
22+
constexpr polymorphic_printer(polymorphic_printer&&) = default;
23+
constexpr polymorphic_printer& operator=(const polymorphic_printer&) = default;
24+
constexpr polymorphic_printer& operator=(polymorphic_printer&&) = default;
2125

2226
virtual STRF_HD ~polymorphic_printer() STRF_DEFAULT_IMPL;
2327

@@ -53,8 +57,6 @@ class printer_wrapper: public detail::polymorphic_printer<CharT>
5357
template <typename CharT>
5458
struct clonable_polymorphic_printer: polymorphic_printer<CharT>
5559
{
56-
virtual STRF_HD ~clonable_polymorphic_printer() STRF_DEFAULT_IMPL;
57-
5860
virtual STRF_HD clonable_polymorphic_printer*
5961
copy_to(void* dst) const = 0;
6062

@@ -142,5 +144,5 @@ using is_string = std::is_base_of<string_input_tag_base, T>;
142144

143145
} // namespace strf
144146

145-
#endif // STRF_DETAIL_PRINTER_HPP
147+
#endif // STRF_DETAIL_POLYMORPHIC_PRINTER_HPP
146148

include/strf/detail/premeasurements.hpp

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@ template <>
1818
class width_accumulator<true>
1919
{
2020
public:
21-
width_accumulator() = default;
21+
constexpr width_accumulator() = default;
2222
~width_accumulator() = default;
23+
constexpr width_accumulator(const width_accumulator&) = default;
24+
constexpr width_accumulator(width_accumulator&&) = default;
25+
constexpr width_accumulator& operator=(const width_accumulator&) = default;
26+
constexpr width_accumulator& operator=(width_accumulator&&) = default;
2327

2428
explicit constexpr STRF_HD width_accumulator(strf::width_t limit) noexcept
2529
: limit_(limit)
@@ -68,8 +72,12 @@ template <>
6872
class width_accumulator<false>
6973
{
7074
public:
71-
7275
constexpr width_accumulator() noexcept = default;
76+
~width_accumulator() noexcept = default;
77+
constexpr width_accumulator(const width_accumulator&) = default;
78+
constexpr width_accumulator(width_accumulator&&) = default;
79+
constexpr width_accumulator& operator=(const width_accumulator&) = default;
80+
constexpr width_accumulator& operator=(width_accumulator&&) = default;
7381

7482
template <typename T>
7583
constexpr STRF_HD void add_width(T) const noexcept
@@ -107,7 +115,12 @@ template <>
107115
class size_accumulator<true>
108116
{
109117
public:
110-
size_accumulator() = default;
118+
constexpr size_accumulator() = default;
119+
~size_accumulator() = default;
120+
constexpr size_accumulator(const size_accumulator&) = default;
121+
constexpr size_accumulator(size_accumulator&&) = default;
122+
constexpr size_accumulator& operator=(const size_accumulator&) = default;
123+
constexpr size_accumulator& operator=(size_accumulator&&) = default;
111124

112125
template < typename IntT
113126
, strf::detail::enable_if_t<std::is_integral<IntT>::value, int> =0>
@@ -116,8 +129,6 @@ class size_accumulator<true>
116129
{
117130
}
118131

119-
~size_accumulator() = default;
120-
121132
template < typename IntT
122133
, strf::detail::enable_if_t<std::is_integral<IntT>::value, int> =0>
123134
STRF_CONSTEXPR_IN_CXX14 STRF_HD void add_size(IntT s) noexcept
@@ -144,8 +155,12 @@ template <>
144155
class size_accumulator<false>
145156
{
146157
public:
147-
148158
constexpr size_accumulator() noexcept = default;
159+
~size_accumulator() noexcept = default;
160+
constexpr size_accumulator(const size_accumulator&) = default;
161+
constexpr size_accumulator(size_accumulator&&) = default;
162+
constexpr size_accumulator& operator=(const size_accumulator&) = default;
163+
constexpr size_accumulator& operator=(size_accumulator&&) = default;
149164

150165
template <typename IntT>
151166
STRF_CONSTEXPR_IN_CXX14 STRF_HD void add_size(IntT) noexcept
@@ -203,8 +218,11 @@ class premeasurements
203218
}
204219

205220
constexpr premeasurements() noexcept = default;
206-
207-
~premeasurements() = default;
221+
~premeasurements() noexcept = default;
222+
constexpr premeasurements(const premeasurements&) = default;
223+
constexpr premeasurements(premeasurements&&) = default;
224+
constexpr premeasurements& operator=(const premeasurements&) = default;
225+
constexpr premeasurements& operator=(premeasurements&&) = default;
208226
};
209227

210228

include/strf/detail/printable_types/bool.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ struct fmt_bool_printer
5252
void STRF_HD operator()(strf::destination<CharT>& dst) const;
5353

5454
strf::encode_fill_f<CharT> encode_fill_ = nullptr;
55-
int fillcount_;
56-
bool value_;
55+
int fillcount_ {};
56+
bool value_ {};
5757
strf::alignment_format afmt_;
58-
strf::lettercase lettercase_;
58+
strf::lettercase lettercase_ = strf::lettercase::lower;
5959
};
6060

6161
template <typename CharT>

include/strf/detail/printable_types/int.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,15 +1139,14 @@ class default_int_printer
11391139
STRF_HD default_int_printer(Pre* pre, UIntT value)
11401140
: uvalue_{value}
11411141
, digcount_{strf::detail::count_digits<10>(value)}
1142-
, negative_{false}
11431142
{
11441143
pre->add_width(digcount_);
11451144
pre->add_size(digcount_);
11461145
}
11471146

11481147
std::uint64_t uvalue_{};
11491148
int digcount_{};
1150-
bool negative_{};
1149+
bool negative_{false};
11511150
};
11521151

11531152
template <typename CharT>
@@ -2057,7 +2056,7 @@ class int_printer_full_dynamic
20572056
other.underlying_printer_().copy_to(&storage_);
20582057
}
20592058

2060-
int_printer_full_dynamic(int_printer_full_dynamic&& other)
2059+
int_printer_full_dynamic(int_printer_full_dynamic&& other) noexcept
20612060
{
20622061
std::move(other.underlying_printer_()).move_to(&storage_);
20632062
}

include/strf/detail/printable_types/string.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1583,7 +1583,7 @@ class transcode_printer_variant
15831583
other.underlying_printer_().copy_to(&storage_);
15841584
}
15851585

1586-
transcode_printer_variant(transcode_printer_variant&& other)
1586+
transcode_printer_variant(transcode_printer_variant&& other) noexcept
15871587
{
15881588
std::move(other.underlying_printer_()).move_to(&storage_);
15891589
}
@@ -1673,7 +1673,7 @@ class aligned_transcode_printer_variant
16731673
{
16741674
other.underlying_printer_().copy_to(&storage_);
16751675
}
1676-
aligned_transcode_printer_variant(aligned_transcode_printer_variant&& other)
1676+
aligned_transcode_printer_variant(aligned_transcode_printer_variant&& other) noexcept
16771677
{
16781678
std::move(other.underlying_printer_()).move_to(&storage_);
16791679
}

include/strf/detail/printing_helpers.hpp

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,36 @@ namespace printing_helpers {
1515
template <typename DefaultValueAndFormat>
1616
struct printable_arg_fmt_remover
1717
{
18+
using fwd_type = typename DefaultValueAndFormat::value_type;
19+
1820
static constexpr STRF_HD decltype(auto) convert_printable_arg
1921
( const DefaultValueAndFormat& x )
2022
{
2123
return x.value();
2224
}
2325
};
2426

27+
template <typename Arg, typename FwdType>
2528
struct printable_arg_forwarder
2629
{
27-
template <typename T>
28-
static constexpr STRF_HD const T& convert_printable_arg(const T& x)
30+
using fwd_type = FwdType;
31+
32+
static constexpr STRF_HD const Arg& convert_printable_arg(const Arg& x)
2933
{
30-
return static_cast<const T&>(x);
34+
return x;
35+
}
36+
};
37+
38+
template <typename PrintableDef, typename... F, typename FwdType>
39+
struct printable_arg_forwarder<value_and_format<PrintableDef, F...>, FwdType>
40+
{
41+
using arg_type = value_and_format<PrintableDef, F...>;
42+
using fwd_type = arg_type;
43+
44+
static constexpr STRF_HD const arg_type& convert_printable_arg
45+
(const arg_type& x)
46+
{
47+
return x;
3148
}
3249
};
3350

@@ -79,7 +96,7 @@ class printable_arg_converter_selector_for_printing_with_premeasurements
7996
, std::declval<const FPack&>()
8097
, std::declval<const A&>() ) ) >
8198
static STRF_HD auto test_(strf::rank<3>*, const A& arg)
82-
-> printable_arg_forwarder;
99+
-> printable_arg_forwarder<A, fwd_type>;
83100

84101
public:
85102
using type =
@@ -279,7 +296,7 @@ class printer_selector_for_printing_without_premeasurements
279296
, std::declval<const FPack&>()
280297
, std::declval<const A&>() ) ) >
281298
static STRF_HD auto test_(strf::rank<7>*, const A& arg)
282-
-> directly_call_print<7, printable_arg_forwarder >;
299+
-> directly_call_print<7, printable_arg_forwarder<A, fwd_type> >;
283300

284301

285302
template < typename P, typename A
@@ -305,7 +322,7 @@ class printer_selector_for_printing_without_premeasurements
305322
, std::declval<const FPack&>()
306323
, std::declval<const A&>() ) ) >
307324
static STRF_HD auto test_(strf::rank<3>*, const A& arg)
308-
-> print_using_make_printer<3, printable_arg_forwarder >;
325+
-> print_using_make_printer<3, printable_arg_forwarder<A, fwd_type> >;
309326

310327
public:
311328
using type =
@@ -319,7 +336,7 @@ struct selector_for_printing_without_premeasurements
319336
{
320337
using traits = strf::printable_def_of<Arg>;
321338
using traits_or_facet_getter =
322-
select_traits_or_facet_getter< traits, CharT, FPack, Arg >;
339+
select_traits_or_facet_getter<traits, CharT, FPack, Arg>;
323340
using traits_or_facet_type = typename traits_or_facet_getter::traits_or_facet_type;
324341

325342
using print_caller = typename
@@ -399,13 +416,13 @@ class polymorphic_printer_that_calls_print_from_facet
399416
};
400417

401418
template <typename CharT, typename FPack, typename PrintableDef, typename Printable>
402-
class polymorphic_printer_that_calls_print_from_traits
419+
class polymorphic_printer_that_calls_print_from_pritable_def
403420
: public detail::polymorphic_printer<CharT>
404421
, private FPack
405422
{
406423
public:
407424

408-
STRF_HD explicit polymorphic_printer_that_calls_print_from_traits
425+
STRF_HD explicit polymorphic_printer_that_calls_print_from_pritable_def
409426
( const printer_adapter_input<FPack, Printable>& i )
410427
: FPack(i.fpack)
411428
, printable_(i.printable)
@@ -435,22 +452,21 @@ template < typename CharT
435452
, typename PrintableArgConverter >
436453
struct print_caller_adapter_maker
437454
{
438-
using converted_printable_type =
439-
decltype(PrintableArgConverter::convert_printable_arg(std::declval<const Arg&>()));
455+
using fwd_type_ = typename PrintableArgConverter::fwd_type;
440456

441457
using polymorphic_printer_type =
442458
detail::conditional_t
443459
< std::is_same<PrintableDef, DefOrFacet>::value
444-
, polymorphic_printer_that_calls_print_from_traits
445-
< CharT, FPack, PrintableDef, converted_printable_type>
460+
, polymorphic_printer_that_calls_print_from_pritable_def
461+
< CharT, FPack, PrintableDef, fwd_type_>
446462
, polymorphic_printer_that_calls_print_from_facet
447-
< CharT, FPack, PrintableDef, converted_printable_type> >;
463+
< CharT, FPack, PrintableDef, fwd_type_> >;
448464

449465
static STRF_HD auto make_polymorphic_printer
450466
( const DefOrFacet&
451467
, const FPack& fp
452468
, const Arg& arg )
453-
-> printer_adapter_input<FPack, converted_printable_type>
469+
-> printer_adapter_input<FPack, fwd_type_>
454470
{
455471
return {fp, PrintableArgConverter::convert_printable_arg(arg)};
456472
}
@@ -498,7 +514,7 @@ class polymorphic_printer_maker_selector_for_printing_without_premeasurements
498514
, std::declval<const A&>() ) ) >
499515
static STRF_HD auto test_(strf::rank<7>*, const A& arg)
500516
-> printer_wrapper_maker_without_premeasurements
501-
< CharT, MakePrinterReturnType, printable_arg_forwarder >;
517+
< CharT, MakePrinterReturnType, printable_arg_forwarder<A, fwd_type> >;
502518

503519
// print_caller_adapter_maker
504520

@@ -527,7 +543,7 @@ class polymorphic_printer_maker_selector_for_printing_without_premeasurements
527543
static STRF_HD auto test_(strf::rank<3>*, const A& arg)
528544
-> print_caller_adapter_maker
529545
< CharT, PrintableDef, DefOrFacet, FPack, Arg
530-
, printable_arg_forwarder >;
546+
, printable_arg_forwarder<A, fwd_type> >;
531547

532548
public:
533549
using type =

include/strf/detail/standard_lib_functions.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ STRF_HD auto addressof(T& arg) noexcept
497497
-> detail::enable_if_t< std::is_object<detail::remove_reference_t<T>>::value, T* >
498498
{
499499
return reinterpret_cast<T*>
500-
( &const_cast<char&>
500+
( &const_cast<char&> // NOLINT(cppcoreguidelines-pro-type-const-cast)
501501
( reinterpret_cast<const volatile char&>(arg) ) );
502502
}
503503

tests/add_and_override_printable_types.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,12 @@ class my_abstract_type
232232
{
233233
public:
234234
my_abstract_type() = default;
235-
STRF_HD virtual ~my_abstract_type() {}
235+
my_abstract_type(const my_abstract_type&) = default;
236+
my_abstract_type(my_abstract_type&&) = default;
237+
my_abstract_type& operator=(const my_abstract_type&) = default;
238+
my_abstract_type& operator=(my_abstract_type&&) = default;
239+
virtual ~my_abstract_type() = default;
240+
236241
STRF_HD virtual const char* msg() const = 0;
237242
};
238243

@@ -241,7 +246,7 @@ class my_derived_type_a: public my_abstract_type
241246
public:
242247
my_derived_type_a() = default;
243248

244-
STRF_HD virtual const char* msg() const override
249+
STRF_HD const char* msg() const override
245250
{
246251
return "aa";
247252
};
@@ -252,7 +257,7 @@ class my_derived_type_b: public my_abstract_type
252257
public:
253258
my_derived_type_b() = default;
254259

255-
STRF_HD virtual const char* msg() const override
260+
STRF_HD const char* msg() const override
256261
{
257262
return "bb";
258263
};
@@ -263,7 +268,7 @@ class my_derived_type_c: public my_abstract_type
263268
public:
264269
my_derived_type_c() = default;
265270

266-
STRF_HD virtual const char* msg() const override
271+
STRF_HD const char* msg() const override
267272
{
268273
return "cc";
269274
};

tests/input_tr_string.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ void STRF_HD test_copy_and_move_tr_print_printer()
451451
auto copy_of_printer = printer0;
452452
printer0(dst0);
453453
copy_of_printer(dst1);
454-
decltype(printer0) printer_from_mv(std::move(printer0));
454+
const decltype(printer0) printer_from_mv(std::move(printer0));
455455
printer_from_mv(dst2);
456456

457457
dst0.finish();

tests/locale.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ void test_locale_numpunct(const char* locale_name)
2121
try{
2222
constexpr double sample = 1.0e+10;
2323

24-
std::locale loc(locale_name);
24+
const std::locale loc(locale_name);
2525

2626
std::wostringstream tmp;
2727
tmp.imbue(loc);

0 commit comments

Comments
 (0)