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