Commit f6df70e5 authored by Kenton Varda's avatar Kenton Varda

GCC doesn't accept (void) to silence warn_unused_result.

This is stupid, but the GCC maintainers refused to change it:

    https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66425

For some reason, KJ's uses of (void) did not warn with GCC 5 but do warn with GCC 7. Supposedly, GCC *never* supported silencing with (void), so there must have been some other bug that caused GCC to fail to trigger the warning previously -- maybe related to the fact that the values being returned are non-trivial types?

C++17 introduces `[[nodiscard]]` which is defined as being squelchable using `(void)`, but we're still on C++14, and KJ_UNUSED_RESULT is a post-declaration attribute so can't be defined in terms of the new C++17 attribute even if the compiler supports it. Sigh.
parent 150da2b0
...@@ -631,7 +631,7 @@ TEST(Async, TaskSet) { ...@@ -631,7 +631,7 @@ TEST(Async, TaskSet) {
EXPECT_EQ(2, counter++); EXPECT_EQ(2, counter++);
})); }));
(void)evalLater([&]() { auto ignore KJ_UNUSED = evalLater([&]() {
KJ_FAIL_EXPECT("Promise without waiter shouldn't execute."); KJ_FAIL_EXPECT("Promise without waiter shouldn't execute.");
}); });
...@@ -725,7 +725,10 @@ TEST(Async, Detach) { ...@@ -725,7 +725,10 @@ TEST(Async, Detach) {
bool ran2 = false; bool ran2 = false;
bool ran3 = false; bool ran3 = false;
(void)evalLater([&]() { ran1 = true; }); // let returned promise be destroyed (canceled) {
// let returned promise be destroyed (canceled)
auto ignore KJ_UNUSED = evalLater([&]() { ran1 = true; });
}
evalLater([&]() { ran2 = true; }).detach([](kj::Exception&&) { ADD_FAILURE(); }); evalLater([&]() { ran2 = true; }).detach([](kj::Exception&&) { ADD_FAILURE(); });
evalLater([]() { KJ_FAIL_ASSERT("foo"){break;} }).detach([&](kj::Exception&& e) { ran3 = true; }); evalLater([]() { KJ_FAIL_ASSERT("foo"){break;} }).detach([&](kj::Exception&& e) { ran3 = true; });
......
...@@ -887,7 +887,9 @@ KJ_TEST("HttpClient canceled write") { ...@@ -887,7 +887,9 @@ KJ_TEST("HttpClient canceled write") {
auto req = client->request(HttpMethod::POST, "/", HttpHeaders(table), uint64_t(4096)); auto req = client->request(HttpMethod::POST, "/", HttpHeaders(table), uint64_t(4096));
// Start a write and immediately cancel it. // Start a write and immediately cancel it.
(void)req.body->write(body.begin(), body.size()); {
auto ignore KJ_UNUSED = req.body->write(body.begin(), body.size());
}
KJ_EXPECT_THROW_MESSAGE("overwrote", req.body->write("foo", 3).wait(waitScope)); KJ_EXPECT_THROW_MESSAGE("overwrote", req.body->write("foo", 3).wait(waitScope));
req.body = nullptr; req.body = nullptr;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment