Add test coverage for vector<bool>::reference
Details
- Reviewers
• Quuxplusone ldionne Mordante - Group Reviewers
Restricted Project - Commits
- rG5d2b8fa155a5: [libc++][test] add vector<bool>::reference tests
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Thanks for doing this!
libcxx/test/std/containers/sequences/vector.bool/reference/assign.pass.cpp | ||
---|---|---|
1 | Naming-wise, IMO we should have assign_bool.pass.cpp and assign_copy.pass.cpp, or something along those lines: the important things are to put the name of the overload set first so that everything in the same overload set sorts together when you ls, and the parameter types explicitly afterward so that you can tell which file contains the overload you care about today. Functionality-wise, I'd like to see a test that assigns false as well as true; and I'd like to see it come ready-made for constexprifying. Something like: bool test() { std::vector<bool> vec; typedef std::vector<bool>::reference Ref; vec.push_back(true); vec.push_back(false); vec.push_back(true); vec.push_back(false); Ref r0 = vec[0]; Ref r1 = vec[1]; { vec[0] = false; vec[1] = true; r0 = r1; assert(vec[0]); assert(vec[1]); } { vec[0] = true; vec[1] = false; r0 = r1; assert(!vec[0]); assert(!vec[1]); } // And then repeat the same two tests for `std::move(r1)`? // And then repeat the same two tests for `static_cast<const Ref&>(r1)`?? return true; } int main(int, char**) { test(); // when constexpr vector is implemented, all we have to do is static_assert(test()); return 0; } All your mains should end with return 0; as well as taking argc, argv, because freestanding wants that. | |
libcxx/test/std/containers/sequences/vector.bool/reference/copy_ctor.pass.cpp | ||
1 | ctor_copy.pass.cpp or something along those lines. Btw, I think it'd be nice also to have some trivial-special-member tests, e.g. LIBCPP_STATIC_ASSERT(!std::is_trivially_constructible<Ref>::value, ""); LIBCPP_STATIC_ASSERT(!std::is_trivially_copy_constructible<Ref>::value, ""); LIBCPP_STATIC_ASSERT(!std::is_trivially_move_constructible<Ref>::value, ""); LIBCPP_STATIC_ASSERT(!std::is_trivially_copy_assignable<Ref>::value, ""); LIBCPP_STATIC_ASSERT(!std::is_trivially_move_assignable<Ref>::value, ""); LIBCPP_STATIC_ASSERT(!std::is_trivially_destructible<Ref>::value, ""); just so we don't break those ABIs by accident. These can go into something like reference/triviality.compile.pass.cpp. | |
libcxx/test/std/containers/sequences/vector.bool/reference/flip.pass.cpp | ||
23 | Let's test !vec[0] directly, and also test that e.g. vec[1] remains unmodified. | |
libcxx/test/std/containers/sequences/vector.bool/reference/operator_bool.pass.cpp | ||
24 | Throw in a static_assert(std::is_convertible<Ref, bool>::value, ""); somewhere near the top. |
LGTM % a couple last nits!
libcxx/test/std/containers/sequences/vector.bool/reference/assign_bool.pass.cpp | ||
---|---|---|
24 ↗ | (On Diff #401641) | Here as well, please test with both true and false. |
libcxx/test/std/containers/sequences/vector.bool/reference/ctor_copy.pass.cpp | ||
22 ↗ | (On Diff #401641) | This test feels insufficient — it's just testing that ref2 refers to some true boolean, not that it refers to the same vec[0] "object" — but I have no great ideas for what would be better here. (We want to test &ref == &ref2 but of course that doesn't work because vector<bool>.) |
libcxx/test/std/containers/sequences/vector.bool/reference/flip.pass.cpp | ||
23 | IMO you could remove assert(!ref) and assert(ref) at this point (lines 22-24, 26, 30), but this is fine too. |
libcxx/test/std/containers/sequences/vector.bool/reference/ctor_copy.pass.cpp | ||
---|---|---|
22 ↗ | (On Diff #401641) | I guess what you could do here is Ref ref2 = ref; assert(ref == ref2 && ref2 == true); ref.flip(); assert(ref == ref2 && ref2 == false); No biggie. |
I only skimmed but this looks OK. I'm surprised we didn't have any tests for that. Please just make sure you looked carefully to avoid duplicating tests that might already exist, but if that's really adding coverage, thanks a lot for doing this!
Naming-wise, IMO we should have assign_bool.pass.cpp and assign_copy.pass.cpp, or something along those lines: the important things are to put the name of the overload set first so that everything in the same overload set sorts together when you ls, and the parameter types explicitly afterward so that you can tell which file contains the overload you care about today.
Functionality-wise, I'd like to see a test that assigns false as well as true; and I'd like to see it come ready-made for constexprifying. Something like:
All your mains should end with return 0; as well as taking argc, argv, because freestanding wants that.