-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[libc++][test] Fixes for hash<Emplaceable>
and value discarding
#126566
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
[libc++][test] Fixes for hash<Emplaceable>
and value discarding
#126566
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`.
@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);
}
|
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.
Thanks, LGTM!
…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`.
…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`.
…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`.
Currently
std::hash<Emplaceable>::operator()
relies implicit conversion fromint
tosize_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 ofat
that wasn't markedTEST_IGNORE_NODISCARD
. This PR adds the missingTEST_IGNORE_NODISCARD
.