Enable -Wunreachable-code-return
authorChristopher Dykes <cdykes@fb.com>
Tue, 13 Dec 2016 18:01:00 +0000 (10:01 -0800)
committerFacebook Github Bot <facebook-github-bot-bot@fb.com>
Tue, 13 Dec 2016 18:03:14 +0000 (10:03 -0800)
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

folly/IPAddress.cpp
folly/Subprocess.cpp
folly/experimental/symbolizer/test/Crash.cpp
folly/fibers/test/FibersTest.cpp
folly/futures/test/FutureTest.cpp
folly/io/async/AsyncTimeout.cpp
folly/io/async/SSLContext.cpp
folly/test/TryTest.cpp

index bb733743376b22a66c88bca7eb189521fa5b5d63..b3ce9ad7740a19553c8a165c7c2f715cc9ab4614 100644 (file)
@@ -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 {
index 93e3f577157a1ad324411eaa3bafdc6ad1292b5f..412a34315c6e1a9a26f861df8adf7d4f9a718751 100644 (file)
@@ -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)
index a84d0763f7f766f5565c56af239e2aeb00422f16..92a4a37efa7df7ea8242779600e4d0454ee2f482 100644 (file)
@@ -19,5 +19,4 @@
 int main() {
   folly::symbolizer::installFatalSignalHandler();
   __builtin_trap();
-  return 0;
 }
index 9a828ad4469e528e8866ec46d1313f72cd43c1ee..d1b60cee6b13c69f9236dce3f4a20a9e49a6f064 100644 (file)
@@ -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));
index 5dc02dd22848d2be9f2a6779066287337bfb2717..b2485a90ea9e57fd27457e4db836c38a8b90d7fb 100644 (file)
@@ -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);
index aa2e2837e07c22516e91b4caa7698aa0c5080fab..736410426e539b3a20ecb8b01b76cb40ab5d70ac 100644 (file)
@@ -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_) {
index cd7ad6e433729fd2be8982877e210c386081e118..43703f2f3a083a02bf3bb66670fbe9793e4e4983 100644 (file)
@@ -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);
index e9b600a35b3c7fe27a1637e8233e5a91b7a04fc1..b00c195b49d536f31decfebc82c3d0579922486d 100644 (file)
@@ -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);