Adding assertions will aid users that have bugs or logic mistakes in their code to receive error messages when debugging.
Details
- Reviewers
ldionne EricWF - Group Reviewers
Restricted Project - Commits
- rG42a024fad9fc: [libc++] Add basic runtime assertions to <semaphore>
Diff Detail
- Repository
- rG LLVM Github Monorepo
Unit Tests
Event Timeline
LGTM, though I spot 4 new checks and 3 new tests. Is there one missing?
libcxx/include/semaphore | ||
---|---|---|
99 | Shouldn't this check be using ::max() rather than the default _LIBPCP_SEMAPHORE_MAX? | |
102 | Please put an empty { } block here to make it more clear that this is intentional. Maybe a comment as well. | |
141 | We should probably add a static assertion that __least_max_value is positive. |
You are correct in observing there are four new assertion but only three checks. There are three checks because one cannot be tested for. max::() is equivalent to the max value of ptrdiff_t so there is no number that can violate this precondition.
I was asked by @ldionne in a previous review to leave the assertion anyway for an identical situation in D154425.
I will see if I can address your other comments with a diff. Thanks for the review.
libcxx/include/semaphore | ||
---|---|---|
99 | Unfortunately I don't think I can. ::max() is a definition that is not part of this class and is defined down in this file so it should not be an available definition right here. |
libcxx/include/semaphore | ||
---|---|---|
107 | I suggest we move to __old > 0 as a drive-by fix too, since it's more consistent with the rest of the code (and it's easier to read, although that is subjective). | |
libcxx/test/libcxx/thread/thread.semaphore/assert.ctor.pass.cpp | ||
12 | This REQUIRES shouldn't be there, otherwise we're basically requiring an old system that didn't have the synchronization library. Along with the XFAIL below, this means that this test was never run. | |
libcxx/test/libcxx/thread/thread.semaphore/assert.release.pass.cpp | ||
12–13 | Same, both these lines should be removed. | |
libcxx/test/std/thread/thread.semaphore/ctor.compile.pass.cpp | ||
33–36 ↗ | (On Diff #541192) | This test is a .compile.pass.cpp, so your expected-error comment is never picked up. You want to move this to a separate .verify.cpp test instead. |
I hope the tests succeed on macosx because they always seem to fail there and that's why I thought about adding the xfail flag. Let's see if removing both does the trick.
Since CI could be considered green since only one runner caused unrelated issues I'm gonna leave my details here for the landing of this revision since I don't have commit access. Thanks to the reviewers.
Edoardo Sanguineti <edoardo.sanguineti222@gmail.com>
Shouldn't this check be using ::max() rather than the default _LIBPCP_SEMAPHORE_MAX?