Skip to content

Commit

Permalink
Address C++ Warnings
Browse files Browse the repository at this point in the history
Remove unneeded casts, as well as perform simplifications that could improve performance.
  • Loading branch information
AZero13 committed Sep 6, 2022
1 parent f9697fc commit 9c91eee
Show file tree
Hide file tree
Showing 48 changed files with 351 additions and 362 deletions.
4 changes: 2 additions & 2 deletions stl/inc/__msvc_int128.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ struct

int64_t __k = 0;
int64_t __t _ZERO_OR_NO_INIT;
for (int __i = 0; __i < static_cast<int>(__n); ++__i) {
for (int __i = 0; __i < __n; ++__i) {
const auto _Prod = static_cast<uint32_t>(__qhat) * static_cast<uint64_t>(__v[__i]);
__t = __u[__i + __j] - __k - static_cast<uint32_t>(_Prod);
__u[__i + __j] = static_cast<uint32_t>(__t);
Expand All @@ -226,7 +226,7 @@ struct
if (__t < 0) {
--__q[__j];
__k = 0;
for (int __i = 0; __i < static_cast<int>(__n); ++__i) {
for (int __i = 0; __i < __n; ++__i) {
__t = __u[__i + __j] + __k + __v[__i];
__u[__i + __j] = static_cast<uint32_t>(__t);
__k = __t >> 32;
Expand Down
9 changes: 4 additions & 5 deletions stl/inc/xcharconv_ryu.h
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ _NODISCARD pair<_CharT*, errc> __d2fixed_buffered_n(_CharT* _First, _CharT* cons

_NODISCARD inline to_chars_result __d2exp_buffered_n(char* _First, char* const _Last, const double __d,
uint32_t __precision) {
char* const _Original_first = _First;
const char* const _Original_first = _First;

const uint64_t __bits = __double_to_bits(__d);

Expand Down Expand Up @@ -1832,11 +1832,11 @@ _NODISCARD inline __floating_decimal_64 __d2d(const uint64_t __ieeeMantissa, con

// Step 4: Find the shortest decimal representation in the interval of valid representations.
int32_t __removed = 0;
uint8_t __lastRemovedDigit = 0;
uint64_t _Output;
// On average, we remove ~2 digits.
if (__vmIsTrailingZeros || __vrIsTrailingZeros) {
// General case, which happens rarely (~0.7%).
uint8_t __lastRemovedDigit = 0;
// General case, which happens rarely (~0.7%).
for (;;) {
const uint64_t __vpDiv10 = __div10(__vp);
const uint64_t __vmDiv10 = __div10(__vm);
Expand Down Expand Up @@ -2331,8 +2331,7 @@ _NODISCARD pair<_CharT*, errc> __d2s_buffered_n(_CharT* const _First, _CharT* co
}

__floating_decimal_64 __v;
const bool __isSmallInt = __d2d_small_int(__ieeeMantissa, __ieeeExponent, &__v);
if (__isSmallInt) {
if (const bool __isSmallInt = __d2d_small_int(__ieeeMantissa, __ieeeExponent, &__v)) {
// For small integers in the range [1, 2^53), __v.__mantissa might contain trailing (decimal) zeros.
// For scientific notation we need to move these zeros into the exponent.
// (This is not needed for fixed-point notation, so it might be beneficial to trim
Expand Down
2 changes: 1 addition & 1 deletion stl/inc/xlocnum
Original file line number Diff line number Diff line change
Expand Up @@ -1241,7 +1241,7 @@ protected:
_OutIt _Dest, ios_base& _Iosbase, _Elem _Fill, bool _Val) const { // put formatted bool to _Dest
if (!(_Iosbase.flags() & ios_base::boolalpha)) {
return do_put(_Dest, _Iosbase, _Fill, static_cast<long>(_Val));
} else { // put "false" or "true"
} else { // put "true" or "false"
const auto& _Punct_fac = _STD use_facet<numpunct<_Elem>>(_Iosbase.getloc());
basic_string<_Elem> _Str;
if (_Val) {
Expand Down
9 changes: 5 additions & 4 deletions stl/inc/xpolymorphic_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ namespace pmr {
}

private:
virtual void* do_allocate(size_t _Bytes, size_t _Align) = 0;
virtual void do_deallocate(void* _Ptr, size_t _Bytes, size_t _Align) = 0;
virtual bool do_is_equal(const memory_resource& _That) const noexcept = 0;
virtual void* do_allocate(size_t _Bytes, size_t _Align) = 0;
virtual void do_deallocate(void* _Ptr, size_t _Bytes, size_t _Align) = 0;
_NODISCARD virtual bool do_is_equal(const memory_resource& _That) const noexcept = 0;
};

_NODISCARD inline bool operator==(const memory_resource& _Left, const memory_resource& _Right) noexcept {
Expand Down Expand Up @@ -269,7 +269,8 @@ namespace pmr {
}

template <class _Uty>
_CXX17_DEPRECATE_POLYMORPHIC_ALLOCATOR_DESTROY void destroy(_Uty* const _Ptr) noexcept /* strengthened */ {
_CXX17_DEPRECATE_POLYMORPHIC_ALLOCATOR_DESTROY void destroy(_Uty* const _Ptr) noexcept
/* strengthened */ {
_Destroy_in_place(*_Ptr);
}

Expand Down
2 changes: 1 addition & 1 deletion stl/src/_tolower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ _CRTIMP2_PURE int __CLRCALL_PURE_OR_CDECL _Tolower(int c, const _Ctypevec* ploc)

// convert wide char to lowercase
size = __crtLCMapStringA(locale_name, LCMAP_LOWERCASE, reinterpret_cast<const char*>(inbuffer), size,
reinterpret_cast<char*>(outbuffer), 3, codepage, TRUE);
reinterpret_cast<char*>(outbuffer), 3, static_cast<int>(codepage), TRUE);

if (size == 0) {
return c;
Expand Down
2 changes: 1 addition & 1 deletion stl/src/_toupper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ _CRTIMP2_PURE int __CLRCALL_PURE_OR_CDECL _Toupper(int c, const _Ctypevec* ploc)

// convert wide char to uppercase
size = __crtLCMapStringA(locale_name, LCMAP_UPPERCASE, reinterpret_cast<const char*>(inbuffer), size,
reinterpret_cast<char*>(outbuffer), 3, codepage, TRUE);
reinterpret_cast<char*>(outbuffer), 3, static_cast<int>(codepage), TRUE);

if (size == 0) {
return c;
Expand Down
5 changes: 3 additions & 2 deletions stl/src/cond.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
#include "primitives.hpp"

struct _Cnd_internal_imp_t { // condition variable implementation for ConcRT
typename std::_Aligned_storage<Concurrency::details::stl_condition_variable_max_size,
Concurrency::details::stl_condition_variable_max_alignment>::type cv;
std::_Aligned_storage_t<Concurrency::details::stl_condition_variable_max_size,
Concurrency::details::stl_condition_variable_max_alignment>
cv;

[[nodiscard]] Concurrency::details::stl_condition_variable_interface* _get_cv() noexcept {
// get pointer to implementation
Expand Down
2 changes: 1 addition & 1 deletion stl/src/cthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void _Thrd_yield() { // surrender remainder of timeslice

// TRANSITION, ABI: _Thrd_equal() is preserved for binary compatibility
_CRTIMP2_PURE int _Thrd_equal(_Thrd_t thr0, _Thrd_t thr1) { // return 1 if thr0 and thr1 identify same thread
return thr0._Id == thr1._Id;
return static_cast<int>(thr0._Id == thr1._Id);
}

// TRANSITION, ABI: _Thrd_current() is preserved for binary compatibility
Expand Down
5 changes: 2 additions & 3 deletions stl/src/iosptrs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ _MRTIMP2 void __cdecl _Atexit(void(__cdecl* pf)()) { // add to wrapup list
struct _Init_atexit { // controller for atexit processing
__CLR_OR_THIS_CALL ~_Init_atexit() noexcept { // process wrapup functions
while (atcount_cdecl < _Nats) {
const auto pf = reinterpret_cast<void(__cdecl*)()>(
DecodePointer(reinterpret_cast<void*>(atfuns_cdecl[atcount_cdecl++])));
if (pf) {
if (const auto pf = reinterpret_cast<void(__cdecl*)()>(
DecodePointer(reinterpret_cast<void*>(atfuns_cdecl[atcount_cdecl++])))) {
pf();
}
}
Expand Down
6 changes: 3 additions & 3 deletions stl/src/locale.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ locale::_Locimp* __CLRCALL_OR_CDECL locale::_Locimp::_Makeloc(

void __CLRCALL_PURE_OR_CDECL locale::_Locimp::_Locimp_ctor(
locale::_Locimp* _This, const locale::_Locimp& imp) { // construct a _Locimp from a copy
if (&imp == _This->_Clocptr) {
if (&imp == _Clocptr) {
_BEGIN_LOCINFO(_Lobj)
_Makeloc(_Lobj, locale::all, _This, nullptr);
_END_LOCINFO()
Expand Down Expand Up @@ -107,15 +107,15 @@ void __CLRCALL_PURE_OR_CDECL locale::_Locimp::_Locimp_ctor(
void __CLRCALL_PURE_OR_CDECL locale::_Locimp::_Locimp_Addfac(
_Locimp* _This, locale::facet* ptrfac, size_t id) { // add a facet to a locale
_BEGIN_LOCK(_LOCK_LOCALE)
const size_t MINCAT = 40; // minimum number of facets in a locale
constexpr size_t MINCAT = 40; // minimum number of facets in a locale

if (_This->_Facetcount <= id) { // make facet vector larger
size_t count = id + 1;
if (count < MINCAT) {
count = MINCAT;
}

locale::facet** ptrnewvec =
const auto ptrnewvec =
static_cast<locale::facet**>(_realloc_crt(_This->_Facetvec, count * sizeof(locale::facet**)));
if (ptrnewvec == nullptr) { // report no memory
_Xbad_alloc();
Expand Down
2 changes: 1 addition & 1 deletion stl/src/locale0.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ _MRTIMP2_PURE locale __CLRCALL_PURE_OR_CDECL locale::empty() { // make empty tra
}

_MRTIMP2_PURE locale::_Locimp* __CLRCALL_PURE_OR_CDECL locale::_Init(bool _Do_incref) { // setup global and "C" locales
locale::_Locimp* ptr = nullptr;
locale::_Locimp* ptr;

_BEGIN_LOCK(_LOCK_LOCALE) // prevent double initialization

Expand Down
11 changes: 5 additions & 6 deletions stl/src/multprec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ static void mul(

void __CLRCALL_PURE_OR_CDECL _MP_Mul(
_MP_arr w, unsigned long long u0, unsigned long long v0) noexcept { // multiply multi-word value by multi-word value
constexpr int m = 2;
constexpr int n = 2;
constexpr unsigned int m = 2;
constexpr unsigned int n = 2;
unsigned long long u[2];
unsigned long long v[2];
u[0] = u0 & mask;
Expand All @@ -63,16 +63,16 @@ void __CLRCALL_PURE_OR_CDECL _MP_Mul(

// Knuth, vol. 2, p. 268, Algorithm M
// M1: [Initialize.]
for (int i = 0; i < m + n + 1; ++i) {
for (unsigned int i = 0; i < m + n + 1; ++i) {
w[i] = 0;
}

for (int j = 0; j < n; ++j) { // M2: [Zero multiplier?]
for (unsigned int j = 0; j < n; ++j) { // M2: [Zero multiplier?]
if (v[j] == 0) {
w[j + m] = 0;
} else { // multiply by non-zero value
unsigned long long k = 0;
int i;
unsigned int i;
// M3: [Initialize i.]
for (i = 0; i < m; ++i) { // M4: [Multiply and add.]
w[i + j] = u[i] * v[j] + w[i + j] + k;
Expand Down Expand Up @@ -170,7 +170,6 @@ void __CLRCALL_PURE_OR_CDECL _MP_Rem(
}
// D5: [Test remainder.]
if (k != 0) { // D6: [Add back.]
--qh;
add(u + j, n + 1, v, n);
}
// D7: [Loop on j.]
Expand Down
5 changes: 3 additions & 2 deletions stl/src/mutex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ extern "C" _CRTIMP2 void __cdecl __set_stl_sync_api_mode(__stl_sync_api_modes_en

struct _Mtx_internal_imp_t { // ConcRT mutex
int type;
typename std::_Aligned_storage<Concurrency::details::stl_critical_section_max_size,
Concurrency::details::stl_critical_section_max_alignment>::type cs;
std::_Aligned_storage_t<Concurrency::details::stl_critical_section_max_size,
Concurrency::details::stl_critical_section_max_alignment>
cs;
long thread_id;
int count;
Concurrency::details::stl_critical_section_interface* _get_cs() { // get pointer to implementation
Expand Down
2 changes: 1 addition & 1 deletion stl/src/nothrow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
#include <new>
_STD_BEGIN

const nothrow_t nothrow = nothrow_t(); // define nothrow
constexpr nothrow_t nothrow = nothrow_t(); // define nothrow
_STD_END
8 changes: 3 additions & 5 deletions stl/src/pplerror.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,10 @@ namespace Concurrency {

#else // defined(_CRT_APP) || defined(UNDOCKED_WINDOWS_UCRT)

namespace Concurrency {
namespace details {
namespace Concurrency::details {

_CRTIMP2 void __thiscall _ExceptionHolder::ReportUnhandledError() {}
_CRTIMP2 void __thiscall _ExceptionHolder::ReportUnhandledError() {}

} // namespace details
} // namespace Concurrency
} // namespace Concurrency::details

#endif // defined(_CRT_APP) || defined(UNDOCKED_WINDOWS_UCRT)
Loading

0 comments on commit 9c91eee

Please sign in to comment.