-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Use memset and memcmp in a bit more cases #1160
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
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
e4f98aa
Use memset in a bit more cases
AdamBucior a112a87
clang-format
AdamBucior 4e95254
Use memcmp with bool
AdamBucior df25b6b
update tests and disable bool == other types
AdamBucior 40bed1c
_INLINE_VAR
AdamBucior 5256769
workaround
AdamBucior 2ed711e
still failing
AdamBucior 86262ed
clang-format
AdamBucior 1b91524
_Fill_memset
AdamBucior 130b731
remove ref and add const
AdamBucior a676793
Fix #1183
AdamBucior 5211954
Simple test case for #1183
AdamBucior 7223a0b
deprecated volatile parameters and return values
AdamBucior e17656f
Code review changes
AdamBucior ec457b1
clang-format
AdamBucior b40d1bb
memcmp with bool == non-bool
AdamBucior c1f04b0
Silence C4806 in <xutility>.
StephanTLavavej File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
These tests will likely pass even if
intis not properly converted tobool. I suggestUh oh!
There was an error while loading. Please reload this page.
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.
On my PC the assertion fails when I run:
And I can't use
memcmpbecause it's not constexprThere 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 think it depends on debug (
/Od) vs release (/O2).Maybe in debug
== trueis literally comparison against true, and in release it is just test and branch on flags.If that's right, then since tests run in debug, this looks enough.
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.
Tested this code in release width /O2 (only replaced
assert(b == true);withif (b != true) abort();becauseassertdoes nothing in release) and it still fails.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.
It mustn't be UB because this code compiles (unless it's a compiler bug):
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.
Also I found that this code compiles:
STL/stl/inc/xutility
Line 4895 in e000d3f
Which means that
equalshould be able to usememcmpwithbool.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.
Interesting.
I think it is still UB (expected behavior is a possible UB manifestation)
Usually wrong
bools act sometimes as true, but apparentlyconstexprevaluation does not trigger that.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.
Maybe
assert(bit_cast<char>(elem) == bit_cast<char>(bool(true)))?Uh oh!
There was an error while loading. Please reload this page.
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.
These tests are not C++20 only so bit_cast is not always available.
And even if it's UB it means that there's no reason for equal not to use
memcmpforbool- not usingmemcmpin this case would only make sense ifbit_cast<bool>((char)2) == truewas always true and we know now that at least sometimes it's not.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.
Also
has_unique_object_representations_v<bool>is true which (I think) means that if twobools have different representations they must compare unequal.