Skip to content

Commit 998f242

Browse files
[libc++][test] Fixes for hash<Emplaceable> and value discarding (#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`.
1 parent 622b8ed commit 998f242

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

libcxx/test/std/containers/Emplaceable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ struct std::hash<Emplaceable> {
4545
typedef Emplaceable argument_type;
4646
typedef std::size_t result_type;
4747

48-
std::size_t operator()(const Emplaceable& x) const { return x.get(); }
48+
std::size_t operator()(const Emplaceable& x) const { return static_cast<std::size_t>(x.get()); }
4949
};
5050

5151
#endif // TEST_STD_VER >= 11

libcxx/test/std/containers/container.adaptors/flat.map/flat.map.access/at_transparent.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ int main(int, char**) {
103103
TransparentComparator c(transparent_used);
104104
std::flat_map<int, int, TransparentComparator> m(std::sorted_unique, {{1, 1}, {2, 2}, {3, 3}}, c);
105105
assert(!transparent_used);
106-
m.at(Transparent<int>{3});
106+
TEST_IGNORE_NODISCARD m.at(Transparent<int>{3});
107107
assert(transparent_used);
108108
}
109109

0 commit comments

Comments
 (0)