[libc++][test] Fixes for hash<Emplaceable> and value discarding#126566
Merged
frederick-vs-ja merged 1 commit intollvm:mainfrom Feb 10, 2025
Merged
Conversation
Currently `std::hash<Emplaceable>::operator()` relies implicit conversion from `int` to `size_t`, which makes MSVC compelling. This PR switches to use `static_cast`. In `flat.map/flat.map.access/at_transparent.pass.cpp`, there's one value-discarding use of `at` that wasn't marked `TEST_IGNORE_NODISCARD`. This PR adds the missing `TEST_IGNORE_NODISCARD`.
Member
|
@llvm/pr-subscribers-libcxx Author: A. Jiang (frederick-vs-ja) ChangesCurrently In Full diff: https://github.com/llvm/llvm-project/pull/126566.diff 2 Files Affected:
diff --git a/libcxx/test/std/containers/Emplaceable.h b/libcxx/test/std/containers/Emplaceable.h
index 1a4e14505fb21ed..001886eece7d75e 100644
--- a/libcxx/test/std/containers/Emplaceable.h
+++ b/libcxx/test/std/containers/Emplaceable.h
@@ -45,7 +45,7 @@ struct std::hash<Emplaceable> {
typedef Emplaceable argument_type;
typedef std::size_t result_type;
- std::size_t operator()(const Emplaceable& x) const { return x.get(); }
+ std::size_t operator()(const Emplaceable& x) const { return static_cast<std::size_t>(x.get()); }
};
#endif // TEST_STD_VER >= 11
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.access/at_transparent.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.access/at_transparent.pass.cpp
index 13edca915fd005c..456f12e0c0d29ff 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.access/at_transparent.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.access/at_transparent.pass.cpp
@@ -103,7 +103,7 @@ int main(int, char**) {
TransparentComparator c(transparent_used);
std::flat_map<int, int, TransparentComparator> m(std::sorted_unique, {{1, 1}, {2, 2}, {3, 3}}, c);
assert(!transparent_used);
- m.at(Transparent<int>{3});
+ TEST_IGNORE_NODISCARD m.at(Transparent<int>{3});
assert(transparent_used);
}
|
Icohedron
pushed a commit
to Icohedron/llvm-project
that referenced
this pull request
Feb 11, 2025
…vm#126566) Currently `std::hash<Emplaceable>::operator()` relies implicit conversion from `int` to `size_t`, which makes MSVC compelling. This PR switches to use `static_cast`. In `flat.map/flat.map.access/at_transparent.pass.cpp`, there's one value-discarding use of `at` that wasn't marked `TEST_IGNORE_NODISCARD`. This PR adds the missing `TEST_IGNORE_NODISCARD`.
joaosaffran
pushed a commit
to joaosaffran/llvm-project
that referenced
this pull request
Feb 14, 2025
…vm#126566) Currently `std::hash<Emplaceable>::operator()` relies implicit conversion from `int` to `size_t`, which makes MSVC compelling. This PR switches to use `static_cast`. In `flat.map/flat.map.access/at_transparent.pass.cpp`, there's one value-discarding use of `at` that wasn't marked `TEST_IGNORE_NODISCARD`. This PR adds the missing `TEST_IGNORE_NODISCARD`.
sivan-shani
pushed a commit
to sivan-shani/llvm-project
that referenced
this pull request
Feb 24, 2025
…vm#126566) Currently `std::hash<Emplaceable>::operator()` relies implicit conversion from `int` to `size_t`, which makes MSVC compelling. This PR switches to use `static_cast`. In `flat.map/flat.map.access/at_transparent.pass.cpp`, there's one value-discarding use of `at` that wasn't marked `TEST_IGNORE_NODISCARD`. This PR adds the missing `TEST_IGNORE_NODISCARD`.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Currently
std::hash<Emplaceable>::operator()relies implicit conversion frominttosize_t, which makes MSVC compelling. This PR switches to usestatic_cast.In
flat.map/flat.map.access/at_transparent.pass.cpp, there's one value-discarding use ofatthat wasn't markedTEST_IGNORE_NODISCARD. This PR adds the missingTEST_IGNORE_NODISCARD.