Skip to content

Commit f6dadc0

Browse files
Some Cpp Core Guidelines warning fixes (#2116)
Co-authored-by: Stephan T. Lavavej <[email protected]>
1 parent c2527c4 commit f6dadc0

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

stl/inc/atomic

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -524,8 +524,8 @@ inline void _Atomic_lock_acquire(long& _Spinlock) noexcept {
524524
// Algorithm from Intel(R) 64 and IA-32 Architectures Optimization Reference Manual, May 2020
525525
// Example 2-4. Contended Locks with Increasing Back-off Example - Improved Version, page 2-22
526526
// The code in mentioned manual is covered by the 0BSD license.
527-
int _Current_backoff = 1;
528-
const int _Max_backoff = 64;
527+
int _Current_backoff = 1;
528+
constexpr int _Max_backoff = 64;
529529
while (_InterlockedExchange(&_Spinlock, 1) != 0) {
530530
while (__iso_volatile_load32(&reinterpret_cast<int&>(_Spinlock)) != 0) {
531531
for (int _Count_down = _Current_backoff; _Count_down != 0; --_Count_down) {

stl/inc/charconv

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -980,7 +980,7 @@ void _Assemble_floating_point_infinity(const bool _Is_negative, _FloatingType& _
980980
_Uint_type _Sign_component = _Is_negative;
981981
_Sign_component <<= _Floating_traits::_Sign_shift;
982982

983-
const _Uint_type _Exponent_component = _Floating_traits::_Shifted_exponent_mask;
983+
constexpr _Uint_type _Exponent_component = _Floating_traits::_Shifted_exponent_mask;
984984

985985
_Result = _Bit_cast<_FloatingType>(_Sign_component | _Exponent_component);
986986
}
@@ -1227,12 +1227,12 @@ _NODISCARD errc _Assemble_floating_point_value_from_big_integer_flt(const _Big_i
12271227
_FloatingType& _Result) noexcept {
12281228
using _Traits = _Floating_type_traits<_FloatingType>;
12291229

1230-
const int32_t _Base_exponent = _Traits::_Mantissa_bits - 1;
1230+
constexpr int32_t _Base_exponent = _Traits::_Mantissa_bits - 1;
12311231

12321232
// Very fast case: If we have 64 bits of precision or fewer,
12331233
// we can just take the two low order elements from the _Big_integer_flt:
12341234
if (_Integer_bits_of_precision <= 64) {
1235-
const int32_t _Exponent = _Base_exponent;
1235+
constexpr int32_t _Exponent = _Base_exponent;
12361236

12371237
const uint32_t _Mantissa_low = _Integer_value._Myused > 0 ? _Integer_value._Mydata[0] : 0;
12381238
const uint32_t _Mantissa_high = _Integer_value._Myused > 1 ? _Integer_value._Mydata[1] : 0;
@@ -1335,7 +1335,7 @@ _NODISCARD errc _Convert_decimal_string_to_floating_type(
13351335
// To generate an N bit mantissa we require N + 1 bits of precision. The extra bit is used to correctly round
13361336
// the mantissa (if there are fewer bits than this available, then that's totally okay;
13371337
// in that case we use what we have and we don't need to round).
1338-
const uint32_t _Required_bits_of_precision = static_cast<uint32_t>(_Traits::_Mantissa_bits + 1);
1338+
constexpr uint32_t _Required_bits_of_precision = static_cast<uint32_t>(_Traits::_Mantissa_bits + 1);
13391339

13401340
// The input is of the form 0.mantissa * 10^exponent, where 'mantissa' are the decimal digits of the mantissa
13411341
// and 'exponent' is the decimal exponent. We decompose the mantissa into two parts: an integer part and a
@@ -2167,7 +2167,7 @@ _NODISCARD to_chars_result _Floating_to_chars_hex_shortest(
21672167
// C11 7.21.6.1 "The fprintf function"/8: "If the value is zero, the exponent is zero."
21682168
// Special-casing zero is necessary because of the exponent.
21692169
const char* const _Str = "0p+0";
2170-
const size_t _Len = 4;
2170+
constexpr size_t _Len = 4;
21712171

21722172
if (_Last - _First < static_cast<ptrdiff_t>(_Len)) {
21732173
return {_Last, errc::value_too_large};

stl/inc/coroutine

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ struct coroutine_handle<noop_coroutine_promise> {
219219

220220
_NODISCARD noop_coroutine_promise& promise() const noexcept {
221221
// Returns a reference to the associated promise
222-
return *reinterpret_cast<noop_coroutine_promise*>(__builtin_coro_promise(_Ptr, 0, false));
222+
return *static_cast<noop_coroutine_promise*>(__builtin_coro_promise(_Ptr, 0, false));
223223
}
224224

225225
_NODISCARD constexpr void* address() const noexcept {

stl/inc/execution

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2813,9 +2813,9 @@ inline size_t _Get_stable_sort_tree_height(const size_t _Count, const size_t _Hw
28132813
const auto _Ideal_chunks = _Hw_threads * _Oversubscription_multiplier;
28142814
const size_t _Log_ideal_chunks = _Floor_of_log_2(_Ideal_chunks);
28152815
#ifdef _WIN64
2816-
const size_t _Max_tree_height = 62; // to avoid ptrdiff_t overflow
2816+
constexpr size_t _Max_tree_height = 62; // to avoid ptrdiff_t overflow
28172817
#else // ^^^ _WIN64 / !_WIN64 vvv
2818-
const size_t _Max_tree_height = 30;
2818+
constexpr size_t _Max_tree_height = 30;
28192819
#endif // _WIN64
28202820
const size_t _Clamped_ideal_chunks = (_STD min)(_Max_tree_height, _Log_ideal_chunks);
28212821

stl/inc/memory_resource

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ namespace pmr {
372372
#endif // _DEBUG
373373
}
374374

375-
_Oversized_header* _Hdr = reinterpret_cast<_Oversized_header*>(reinterpret_cast<char*>(_Ptr) + _Bytes) - 1;
375+
_Oversized_header* _Hdr = reinterpret_cast<_Oversized_header*>(static_cast<char*>(_Ptr) + _Bytes) - 1;
376376

377377
_STL_ASSERT(_Hdr->_Size == _Bytes && _Hdr->_Align == _Align,
378378
"Cannot deallocate memory not allocated by this memory pool.");

0 commit comments

Comments
 (0)