Commit 4824fb83 authored by Christopher Dykes's avatar Christopher Dykes Committed by Facebook Github Bot

Enable -Wunreachable-code-return

Summary: The most common place this happened was in tests where it was being used to force the return type of a lambda, but there were a couple of places in the main code that triggered this as well.

Reviewed By: yfeldblum

Differential Revision: D4310187

fbshipit-source-id: e3701cff9827eacaf3be8d28296441466eb2fa11
parent ab1bf671
......@@ -420,7 +420,6 @@ IPAddress::longestCommonPrefix(const CIDRNetwork& one, const CIDRNetwork& two) {
} else {
throw std::invalid_argument("Unknown address family");
}
return {IPAddress(0), uint8_t(0)};
}
[[noreturn]] void IPAddress::asV4Throw() const {
......
......@@ -34,6 +34,7 @@
#include <glog/logging.h>
#include <folly/Assume.h>
#include <folly/Conv.h>
#include <folly/Exception.h>
#include <folly/ScopeGuard.h>
......@@ -106,8 +107,7 @@ std::string ProcessReturnCode::str() const {
return to<std::string>("killed by signal ", killSignal(),
(coreDumped() ? " (core dumped)" : ""));
}
CHECK(false); // unreached
return ""; // silence GCC warning
assume_unreachable();
}
CalledProcessError::CalledProcessError(ProcessReturnCode rc)
......
......@@ -19,5 +19,4 @@
int main() {
folly::symbolizer::installFatalSignalHandler();
__builtin_trap();
return 0;
}
......@@ -678,12 +678,11 @@ TEST(FiberManager, collectNThrow) {
manager.addTask([&]() {
std::vector<std::function<int()>> funcs;
for (size_t i = 0; i < 3; ++i) {
funcs.push_back([i, &pendingFibers]() {
funcs.push_back([i, &pendingFibers]() -> size_t {
await([&pendingFibers](Promise<int> promise) {
pendingFibers.push_back(std::move(promise));
});
throw std::runtime_error("Runtime");
return i * 2 + 1;
});
}
......@@ -2029,9 +2028,8 @@ TEST(FiberManager, ABD_UserProvidedBatchDispatchThrowsTest) {
// Testing that exception is set if user provided batch dispatch throws
//
dispatchFunc = [](std::vector<ValueT>&& inputs) -> std::vector<ResultT> {
auto results = userDispatchFunc(std::move(inputs));
(void)userDispatchFunc(std::move(inputs));
throw std::runtime_error("Unexpected exception in user dispatch function");
return results;
};
auto atomicBatchDispatcher =
createAtomicBatchDispatcher(std::move(dispatchFunc));
......
......@@ -237,18 +237,16 @@ TEST(Future, onError) {
// Returned value propagates
{
auto f = makeFuture().then([] {
auto f = makeFuture().then([]() -> int {
throw eggs;
return 0;
}).onError([&](eggs_t& /* e */) { return 42; });
EXPECT_EQ(42, f.value());
}
// Returned future propagates
{
auto f = makeFuture().then([] {
auto f = makeFuture().then([]() -> int {
throw eggs;
return 0;
}).onError([&](eggs_t& /* e */) { return makeFuture<int>(42); });
EXPECT_EQ(42, f.value());
}
......@@ -256,15 +254,15 @@ TEST(Future, onError) {
// Throw in callback
{
auto f = makeFuture()
.then([] { throw eggs; return 0; })
.onError([&] (eggs_t& e) { throw e; return -1; });
.then([]() -> int { throw eggs; })
.onError([&] (eggs_t& e) -> int { throw e; });
EXPECT_THROW(f.value(), eggs_t);
}
{
auto f = makeFuture()
.then([] { throw eggs; return 0; })
.onError([&] (eggs_t& e) { throw e; return makeFuture<int>(-1); });
.then([]() -> int { throw eggs; })
.onError([&] (eggs_t& e) -> Future<int> { throw e; });
EXPECT_THROW(f.value(), eggs_t);
}
......@@ -283,14 +281,12 @@ TEST(Future, onError) {
// exception_wrapper, return Future<T> but throw
{
auto f = makeFuture()
.then([] {
.then([]() -> int {
throw eggs;
return 0;
})
.onError([&](exception_wrapper /* e */) {
.onError([&](exception_wrapper /* e */) -> Future<int> {
flag();
throw eggs;
return makeFuture<int>(-1);
});
EXPECT_FLAG();
EXPECT_THROW(f.value(), eggs_t);
......@@ -299,9 +295,8 @@ TEST(Future, onError) {
// exception_wrapper, return T
{
auto f = makeFuture()
.then([] {
.then([]() -> int {
throw eggs;
return 0;
})
.onError([&](exception_wrapper /* e */) {
flag();
......@@ -314,14 +309,12 @@ TEST(Future, onError) {
// exception_wrapper, return T but throw
{
auto f = makeFuture()
.then([] {
.then([]() -> int {
throw eggs;
return 0;
})
.onError([&](exception_wrapper /* e */) {
.onError([&](exception_wrapper /* e */) -> int {
flag();
throw eggs;
return -1;
});
EXPECT_FLAG();
EXPECT_THROW(f.value(), eggs_t);
......
......@@ -128,9 +128,7 @@ void AsyncTimeout::detachTimeoutManager() {
// currently installed.
if (isScheduled()) {
// Programmer bug. Abort the program.
LOG(ERROR) << "detachEventBase() called on scheduled timeout; aborting";
abort();
return;
LOG(FATAL) << "detachEventBase() called on scheduled timeout; aborting";
}
if (timeoutManager_) {
......
......@@ -169,12 +169,10 @@ void SSLContext::setServerECCurve(const std::string& curveName) {
nid = OBJ_sn2nid(curveName.c_str());
if (nid == 0) {
LOG(FATAL) << "Unknown curve name:" << curveName.c_str();
return;
}
ecdh = EC_KEY_new_by_curve_name(nid);
if (ecdh == nullptr) {
LOG(FATAL) << "Unable to create curve:" << curveName.c_str();
return;
}
SSL_CTX_set_tmp_ecdh(ctx_, ecdh);
......
......@@ -64,9 +64,8 @@ TEST(Try, makeTryWith) {
}
TEST(Try, makeTryWithThrow) {
auto func = []() {
auto func = []() -> std::unique_ptr<int> {
throw std::runtime_error("Runtime");
return folly::make_unique<int>(1);
};
auto result = makeTryWith(func);
......@@ -85,7 +84,6 @@ TEST(Try, makeTryWithVoid) {
TEST(Try, makeTryWithVoidThrow) {
auto func = []() {
throw std::runtime_error("Runtime");
return;
};
auto result = makeTryWith(func);
......
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