-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix some C++ warnings #3079
Fix some C++ warnings #3079
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be better if one warning type at a time is addressed
On a more general note of development. You might want to have more descriptive commit messages rather than "Update filename". We know you are updating/changing the file. Commits should have a message that states what you're doing. like "made auto cp , auto *cp to distinguish pointer" |
Also, you might want to tell us in the pr header why you made these changes or what motivated you do these changes. Just saying fixing some C++ warnings is very generic. |
In Visual Studio, at least, you can use Ctrl+K, Ctrl+D to format an entire file. It seems like you could save some effort (and CI resources) by first doing this on every file you've modified. |
fd91cfc
to
c9d93e6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good on files I did not add comments on, on files that I did, there are comments about a few nits I have.
I think this PR is tackling too much at once, hence very difficult to review as a whole. It would be nice if there was a dedicated PR to tackle certain kinds of warnings at a time. |
8cf7ff5
to
9c91eee
Compare
While I appreciate the effort in this PR, I think that maintainers or someone else should take over the changes in this PR (and split them into separate PR's that are grouped together each with similar changes). Because of this I feel that in the current state this PR is in that it is not worth merging as it's just too large to review with a lot of unrelated whitespace changes that make review unrealistically harder to do. Also the force pushes did not need to be used because squash merging usually is used (I think) anyway. |
After thinking about it more, I fail to see the point of fixing these warnings so that they do not show up when using /Wall, however I personally never use /Wall as I find it is not worth it because usually it emits warnings that are false positives and so I usually use up to /W3 or /W4. In this case if you use /Wall you deserve to get false positive warnings because you asked for all warnings (even ones that can emit false positives). |
Thanks for looking into improving the codebase. However, as other contributors have mentioned, there is way too much happening in this PR, and with no explanation. I've previously explained in #2766 (comment) why "grab bag" PRs with no descriptions are risky and costly to review. (There are also some behavioral changes mixed in here, which are even riskier.) While we're interested in long-term codebase health and merge a significant number of code cleanups over time, we are also quite busy with feature/bugfix work, so it's important for "nice to have" enhancements to be low risk and easy to understand/review. Additionally, as Casey previously explained in #2083 (comment), force-pushes should be avoided in microsoft/STL PRs - they make incremental reviewing difficult. (In rare situations they can be reasonable, but this is not one of them.) I note that the STL currently attempts to be Please let us know if you're interested in decomposing this PR into a series of small, focused PRs with explanations, where we can easily decide whether to merge each category of changes. (For example, changing |
I am very interested |
7ffef35
to
f98abc8
Compare
f2284bd
to
dbc16a1
Compare
Remove unneeded casts, as well as perform simplifications that could improve performance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with the sentiment that changes like this are too broad to perform in one commit like this. With that said, I've looked over the changes made and offered some suggestions. Here are some key notes:
- I like the additions of
constexpr
where they can be used. Those should go into their own PR, in my opinion. - A number of changes here are either redundant or appear to conflict with the style conventions used in the rest of the codebase. These will need to be resolved.
- At least one change seems to affect the logic of the code (specifically, the change to remove
--qh
in the_MP_Rem()
function found inmultprec.cpp
). If you removed this because it was a bug, then that should probably go in a separate PR.
@@ -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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const char* const _Original_first = _First; | |
const char* const _Original_first = _First; |
The leading whitespace is unnecessary. Other than that, more const
is never a bad thing!
uint8_t __lastRemovedDigit = 0; | ||
// General case, which happens rarely (~0.7%). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uint8_t __lastRemovedDigit = 0; | |
// General case, which happens rarely (~0.7%). | |
// General case, which happens rarely (~0.7%). | |
uint8_t __lastRemovedDigit = 0; |
More bad whitespace detected. Also, I feel like the comment should be above the variable declaration. However, moving __lastRemovedDigit
to its most necessary scope is a good change.
@@ -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)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (const bool __isSmallInt = __d2d_small_int(__ieeeMantissa, __ieeeExponent, &__v)) { | |
if (__d2d_small_int(__ieeeMantissa, __ieeeExponent, &__v)) { |
Better yet, just remove __isSmallInt
altogether if that is its only purpose. (To be fair, I will do things like const bool isSomethingTrue = [. . .];
in my own code if the defining expression is really long or not very self-explanatory, but the comment beneath the if
-statement backs up what is going on here and when this case is hit.)
@@ -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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is kind of silly, in my opinion. I guess "true or false" rolls off of the tongue better than "false or true," but is something like this really worth the effort?
No changes are suggested here. Keep in mind, however, that reviewers have to look over every change you make. (I still feel bad for the reviewers who had to endure the copious amounts of non-conformance and style differences in my own PR.)
const int dstlen = | ||
__crtLCMapStringA(locale_name, LCMAP_SORTKEY, string2, static_cast<int>(n2), nullptr, 0, codepage, TRUE); | ||
const int dstlen = __crtLCMapStringA( | ||
locale_name, LCMAP_SORTKEY, string2, static_cast<int>(n2), nullptr, 0, static_cast<int>(codepage), TRUE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Much like before, the static_cast
here is redundant, since the exact same operation is applied with it as without it. It's just a stylistic choice, so I would suggest sticking with what others seem to do in similar scenarios.
A similar situation occurs below.
int ret = 0; | ||
int n1 = static_cast<int>(end1 - string1); | ||
int n2 = static_cast<int>(end2 - string2); | ||
int ret; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine, but perhaps ret
could be moved further down to just before its first uses.
No changes are requested here.
@@ -46,7 +46,7 @@ _EXTERN_C_UNLESS_PURE | |||
// Non-standard: if OM/API error, return INT_MAX. | |||
_CRTIMP2_PURE size_t __CLRCALL_PURE_OR_CDECL _Wcsxfrm(_Out_writes_(end1 - string1) _Post_readable_size_(return ) | |||
wchar_t* string1, | |||
_In_z_ wchar_t* end1, const wchar_t* string2, const wchar_t* end2, const _Collvec* ploc) { | |||
_In_z_ const wchar_t* end1, const wchar_t* string2, const wchar_t* end2, const _Collvec* ploc) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_In_z_ const wchar_t* end1, const wchar_t* string2, const wchar_t* end2, const _Collvec* ploc) { | |
_In_z_ wchar_t* end1, const wchar_t* string2, const wchar_t* end2, const _Collvec* ploc) { |
Again, the addition of const
here, while safer, could break existing code. In an ideal world, we would just be able to add const
, and everything would be great. In reality, I can see this causing havoc somewhere, unless you are sure that the function is only called with const wchar_t*
values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, it's not always called with const wchar_t* some devs might need to use it without it being const.
@@ -56,7 +56,7 @@ _CRTIMP2_PURE _Cvtvec __CLRCALL_PURE_OR_CDECL _Getcvt() { // get conversion info | |||
// None. | |||
|
|||
_CRTIMP2_PURE _Success_(return != -1) int __CLRCALL_PURE_OR_CDECL | |||
_Wcrtomb(_Out_ char* s, wchar_t wchar, mbstate_t* pst, const _Cvtvec* ploc) { | |||
_Wcrtomb(_Out_ char* s, wchar_t wchar, const mbstate_t* pst, const _Cvtvec* ploc) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_Wcrtomb(_Out_ char* s, wchar_t wchar, const mbstate_t* pst, const _Cvtvec* ploc) { | |
_Wcrtomb(_Out_ char* s, wchar_t wchar, mbstate_t* pst, const _Cvtvec* ploc) { |
It's just more of the same "this-parameter-really-should-have-const-but-we-can't-just-change-it-now" stuff.
Please stop squashing and force pushing. Take a look at this PR #2861 by @StephanTLavavej and take note how he has split the changes into separate commits for ease of review |
No description provided.