Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
| libcxx/include/__node_handle | ||
|---|---|---|
| 16 | Nit: suggest removing this comment line, as it'll just bit-rot. | |
| 46 | // nodiscard since C++20 | |
| libcxx/test/std/containers/container.node/node_handle.empty.nodiscard.verify.cpp | ||
| 16 | extract and empty were added in C++17, so we should have a C++17 test for this. It looks like we mark empty as nodiscard only "AFTER_CXX17"; we should also test that it's marked, as an extension, in C++17 mode. We have existing tests for nodiscard extensions in | |
| 25 | I suggest populating this container, to avoid the appearance of trying to extract from an empty container. (Even if this test is compile-only, which I think it is, despite the main routine.) template<class Container>
void test_one(Container c) {
auto n = c.extract(c.begin());
n.empty(); // expected-warning 8{{ignoring return value of function}}
}
void test() {
test_one(std::set<int>{1});
test_one(std::multiset<int>{1});
test_one(std::map<int, int>{{1, 1}});
test_one(std::multimap<int, int>{{1, 1}});
test_one(std::unordered_set<int>{1});
test_one(std::unordered_multiset<int>{1});
test_one(std::unordered_map<int, int>{{1, 1}});
test_one(std::unordered_multimap<int, int>{{1, 1}});
}(and no main routine). However, see my other comment. | |
D99895 is related, btw (and I just landed it, so rebase before attempting to mess with libcxx/test/libcxx/diagnostics if you're going that route).
FWIW, LGTM at this point except that I still think I'd prefer to see this tested in test/libcxx/diagnostics/nodiscard_extensions.verify.cpp.
Even if it's not an extension?
| libcxx/include/__node_handle | ||
|---|---|---|
| 46 | Done and used /* */. | |
| libcxx/test/std/containers/container.node/node_handle.empty.nodiscard.verify.cpp | ||
| 16 | Not sure if I understand you correctly, you want to have all the tests there or only those for the C++17 extension? Also, adding [[nodiscard]] as an extension would mean having this ugliness (or adding yet another macro): #if _LIBCPP_STD_VER <= 17
_LIBCPP_NODISCARD_EXT
#endif
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
bool empty() const { return __ptr_ == nullptr; } | |
| libcxx/test/std/containers/container.node/node_handle.empty.nodiscard.verify.cpp | ||
|---|---|---|
| 16 | IIUC, if the user defines -D_LIBCPP_ENABLE_NODISCARD=1, then _LIBCPP_NODISCARD_AFTER_CXX17 expands to [[nodiscard]] in all supported modes (yes even C++11/14/17). Basically, _LIBCPP_NODISCARD_AFTER_CXX17 already implies "WG21 has decided that making this [[nodiscard]] is a good idea," which implies "making this [[nodiscard]] is always a good idea." So it already implies the extension. We just need tests for the extension. I had intended "all the tests there," but I'm not confident in that — I now think it's likely that your tests here should stay here, but the C++17 extension tests should go over there. You'll have to take a look at those files and see how they're currently organized. | |
Since this is mandated I think it makes sense to add the test here. IMO it doesn't belong to the extension tests.
| libcxx/test/std/containers/container.node/node_handle.empty.nodiscard.verify.cpp | ||
|---|---|---|
| 25 | This is indeed a compile-time test. It tests whether the expected compiler diagnostics are issues. Basically this is our typical clang unit test. | |
I wasn't aware of this change and I did the same thing in D109027. Apologies for the duplicated effort.
Abandoning since this was done in a different change, to clear up the review queue and help avoid these issues!
Nit: suggest removing this comment line, as it'll just bit-rot.