Allow building with -Wmissing-noreturn
authorChristopher Dykes <cdykes@fb.com>
Wed, 14 Dec 2016 06:05:21 +0000 (22:05 -0800)
committerFacebook Github Bot <facebook-github-bot-bot@fb.com>
Wed, 14 Dec 2016 06:17:58 +0000 (22:17 -0800)
Summary: If your function doesn't return you should be explicit about it.

Reviewed By: meyering

Differential Revision: D4309893

fbshipit-source-id: ce275ec8f42e2cb3253a1e40e263934649f09d9e

17 files changed:
folly/FixedString.h
folly/MallctlHelper.cpp
folly/MallctlHelper.h
folly/detail/ThreadLocalDetail.h
folly/experimental/DynamicParser.cpp
folly/experimental/DynamicParser.h
folly/experimental/exception_tracer/ExceptionTracerTest.cpp
folly/experimental/exception_tracer/test/ExceptionCounterTest.cpp
folly/fibers/Fiber.cpp
folly/fibers/Fiber.h
folly/ssl/OpenSSLHash.cpp
folly/ssl/OpenSSLHash.h
folly/test/SafeAssertTest.cpp
folly/test/ScopeGuardTest.cpp
folly/test/SubprocessTestParentDeathHelper.cpp
folly/test/function_benchmark/test_functions.cpp
folly/test/function_benchmark/test_functions.h

index 0f00e6edd32c7beffa4f30b2597108ed09d3c33d..6291ffeb709519bbd9c42351d285b69e2cdbaa9b 100644 (file)
@@ -102,19 +102,11 @@ constexpr std::size_t checkOverflowOrNpos(std::size_t i, std::size_t max) {
 }
 
 // Intentionally NOT constexpr. See note above for assertOutOfBounds
 }
 
 // Intentionally NOT constexpr. See note above for assertOutOfBounds
-inline void assertOutOfBoundsNothrow() {
-  assert(false && "Array index out of bounds in BasicFixedString");
-}
-
-constexpr std::size_t checkOverflowNothrow(std::size_t i, std::size_t max) {
-  return i <= max ? i : (assertOutOfBoundsNothrow(), i);
-}
-
-// Intentionally NOT constexpr. See note above for assertOutOfBounds
-inline void assertNotNullTerminated() noexcept {
+[[noreturn]] inline void assertNotNullTerminated() noexcept {
   assert(
       false &&
       "Non-null terminated string used to initialize a BasicFixedString");
   assert(
       false &&
       "Non-null terminated string used to initialize a BasicFixedString");
+  std::terminate(); // Fail hard, fail fast.
 }
 
 // Parsing help for human readers: the following is a constexpr noexcept
 }
 
 // Parsing help for human readers: the following is a constexpr noexcept
@@ -1153,7 +1145,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase {
 #ifdef NDEBUG
     return data_[i];
 #else
 #ifdef NDEBUG
     return data_[i];
 #else
-    return data_[detail::fixedstring::checkOverflowNothrow(i, size_)];
+    return data_[detail::fixedstring::checkOverflow(i, size_)];
 #endif
   }
 
 #endif
   }
 
@@ -1164,21 +1156,21 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase {
 #ifdef NDEBUG
     return data_[i];
 #else
 #ifdef NDEBUG
     return data_[i];
 #else
-    return data_[detail::fixedstring::checkOverflowNothrow(i, size_)];
+    return data_[detail::fixedstring::checkOverflow(i, size_)];
 #endif
   }
 
   /**
    * \note Equivalent to `(*this)[0]`
    */
 #endif
   }
 
   /**
    * \note Equivalent to `(*this)[0]`
    */
-  FOLLY_CPP14_CONSTEXPR Char& front() noexcept(false) {
+  FOLLY_CPP14_CONSTEXPR Char& front() noexcept {
     return (*this)[0u];
   }
 
   /**
    * \overload
    */
     return (*this)[0u];
   }
 
   /**
    * \overload
    */
-  constexpr const Char& front() const noexcept(false) {
+  constexpr const Char& front() const noexcept {
     return (*this)[0u];
   }
 
     return (*this)[0u];
   }
 
@@ -1186,22 +1178,22 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase {
    * \note Equivalent to `at(size()-1)`
    * \pre `!empty()`
    */
    * \note Equivalent to `at(size()-1)`
    * \pre `!empty()`
    */
-  FOLLY_CPP14_CONSTEXPR Char& back() noexcept(false) {
+  FOLLY_CPP14_CONSTEXPR Char& back() noexcept {
 #ifdef NDEBUG
     return data_[size_ - 1u];
 #else
 #ifdef NDEBUG
     return data_[size_ - 1u];
 #else
-    return data_[size_ - detail::fixedstring::checkOverflowNothrow(1u, size_)];
+    return data_[size_ - detail::fixedstring::checkOverflow(1u, size_)];
 #endif
   }
 
   /**
    * \overload
    */
 #endif
   }
 
   /**
    * \overload
    */
-  constexpr const Char& back() const noexcept(false) {
+  constexpr const Char& back() const noexcept {
 #ifdef NDEBUG
     return data_[size_ - 1u];
 #else
 #ifdef NDEBUG
     return data_[size_ - 1u];
 #else
-    return data_[size_ - detail::fixedstring::checkOverflowNothrow(1u, size_)];
+    return data_[size_ - detail::fixedstring::checkOverflow(1u, size_)];
 #endif
   }
 
 #endif
   }
 
index 7e224d0817a594048f49820ba1eb78ad843013f1..a9c0c397e63b840835d82ebe4d9a80b69f4a5a86 100644 (file)
@@ -24,7 +24,7 @@ namespace folly {
 
 namespace detail {
 
 
 namespace detail {
 
-void handleMallctlError(const char* cmd, int err) {
+[[noreturn]] void handleMallctlError(const char* cmd, int err) {
   assert(err != 0);
   throw std::runtime_error(
       sformat("mallctl {}: {} ({})", cmd, errnoStr(err), err));
   assert(err != 0);
   throw std::runtime_error(
       sformat("mallctl {}: {} ({})", cmd, errnoStr(err), err));
index 5c66c476642508789bdae71b58aa62bccf335629..2d74205d374c01d5a45a4cc75306c827f3b339a1 100644 (file)
@@ -27,7 +27,7 @@ namespace folly {
 
 namespace detail {
 
 
 namespace detail {
 
-void handleMallctlError(const char* cmd, int err);
+[[noreturn]] void handleMallctlError(const char* cmd, int err);
 
 template <typename T>
 void mallctlHelper(const char* cmd, T* out, T* in) {
 
 template <typename T>
 void mallctlHelper(const char* cmd, T* out, T* in) {
index c04fee1eb95e53213d853b4a8fb24f26ec2021cd..418889ff117b3b6d401f47e3a2f70381de9f20ce 100644 (file)
@@ -256,7 +256,7 @@ struct StaticMetaBase {
 
   StaticMetaBase(ThreadEntry* (*threadEntry)(), bool strict);
 
 
   StaticMetaBase(ThreadEntry* (*threadEntry)(), bool strict);
 
-  ~StaticMetaBase() {
+  [[noreturn]] ~StaticMetaBase() {
     LOG(FATAL) << "StaticMeta lives forever!";
   }
 
     LOG(FATAL) << "StaticMeta lives forever!";
   }
 
index 4038af97f50087fcb87b73eebc160b59edba65c6..18dd25fd1b5baab04ca6412e9f9c13618cf29ec7 100644 (file)
@@ -168,7 +168,7 @@ folly::dynamic DynamicParser::ParserStack::releaseErrors() {
   return releaseErrorsImpl();
 }
 
   return releaseErrorsImpl();
 }
 
-void DynamicParser::ParserStack::throwErrors() {
+[[noreturn]] void DynamicParser::ParserStack::throwErrors() {
   throw DynamicParserParseError(releaseErrorsImpl());
 }
 
   throw DynamicParserParseError(releaseErrorsImpl());
 }
 
index 4124d8ca6613cfa17e94d377f736230a742f2741..8541313fa1c6e701aa367076404317e26b0c5be2 100644 (file)
@@ -357,9 +357,9 @@ private:
     folly::dynamic releaseErrors();
 
     // Invoked on error when using OnError::THROW.
     folly::dynamic releaseErrors();
 
     // Invoked on error when using OnError::THROW.
-    void throwErrors();
+    [[noreturn]] void throwErrors();
 
 
-  private:
+   private:
     friend struct Pop;
 
     folly::dynamic releaseErrorsImpl();  // for releaseErrors() & throwErrors()
     friend struct Pop;
 
     folly::dynamic releaseErrorsImpl();  // for releaseErrors() & throwErrors()
index 2db6f9f86f78e00d706ed587607182a4bdaaaa47..25a66524661b59d922ac92a8f825caa409f35df8 100644 (file)
@@ -20,7 +20,7 @@
 
 #include <folly/experimental/exception_tracer/ExceptionTracer.h>
 
 
 #include <folly/experimental/exception_tracer/ExceptionTracer.h>
 
-void bar() {
+[[noreturn]] void bar() {
   throw std::runtime_error("hello");
 }
 
   throw std::runtime_error("hello");
 }
 
@@ -45,7 +45,7 @@ void foo() {
   }
 }
 
   }
 }
 
-void baz() {
+[[noreturn]] void baz() {
   try {
     try {
       bar();
   try {
     try {
       bar();
index 706177b85c21f563d4b86ba3f52fb4e32cbc31fc..6751396b2ef8db05d859ed324bb512c6d3028aa5 100644 (file)
 
 struct MyException {};
 
 
 struct MyException {};
 
-void bar() { throw std::runtime_error("hello"); }
+[[noreturn]] void bar() {
+  throw std::runtime_error("hello");
+}
 
 
-void foo() { throw MyException(); }
+[[noreturn]] void foo() {
+  throw MyException();
+}
 
 
-void baz() { foo(); }
+[[noreturn]] void baz() {
+  foo();
+}
 
 using namespace folly::exception_tracer;
 
 
 using namespace folly::exception_tracer;
 
index de4124f77d14447a1a32fbf124b397d031dc4ab0..6caa9d551de08f6635cfc9853607cf7dc01f3366 100644 (file)
@@ -118,7 +118,7 @@ void Fiber::recordStackPosition() {
   VLOG(4) << "Stack usage: " << currentPosition;
 }
 
   VLOG(4) << "Stack usage: " << currentPosition;
 }
 
-void Fiber::fiberFunc() {
+[[noreturn]] void Fiber::fiberFunc() {
 #ifdef FOLLY_SANITIZE_ADDRESS
   fiberManager_.registerFinishSwitchStackWithAsan(
       nullptr, &asanMainStackBase_, &asanMainStackSize_);
 #ifdef FOLLY_SANITIZE_ADDRESS
   fiberManager_.registerFinishSwitchStackWithAsan(
       nullptr, &asanMainStackBase_, &asanMainStackSize_);
index c43894f2e262c9e96b9dd2e32a4dab6004f5f35a..82b73bc6490c1daec0f6751c8adc35e6feb3473d 100644 (file)
@@ -90,7 +90,7 @@ class Fiber {
   template <typename F, typename G>
   void setFunctionFinally(F&& func, G&& finally);
 
   template <typename F, typename G>
   void setFunctionFinally(F&& func, G&& finally);
 
-  void fiberFunc();
+  [[noreturn]] void fiberFunc();
 
   /**
    * Switch out of fiber context into the main context,
 
   /**
    * Switch out of fiber context into the main context,
index 9e3581aa4ee2bdde8bf06effe46246b349e0372d..7b1c439470518bf54fce94e232eb9aff409a6b08 100644 (file)
 namespace folly {
 namespace ssl {
 
 namespace folly {
 namespace ssl {
 
-void OpenSSLHash::check_out_size_throw(size_t size, MutableByteRange out) {
+[[noreturn]] void OpenSSLHash::check_out_size_throw(
+    size_t size,
+    MutableByteRange out) {
   throw std::invalid_argument(folly::sformat(
       "expected out of size {} but was of size {}", size, out.size()));
 }
 
   throw std::invalid_argument(folly::sformat(
       "expected out of size {} but was of size {}", size, out.size()));
 }
 
-void OpenSSLHash::check_libssl_result_throw() {
+[[noreturn]] void OpenSSLHash::check_libssl_result_throw() {
   throw std::runtime_error("openssl crypto function failed");
 }
 
   throw std::runtime_error("openssl crypto function failed");
 }
 
index 5081faec14b40beee50df775284383f6a8dc6673..2a89e64b126cc17d0425497f356a08f832fd5812 100644 (file)
@@ -173,7 +173,9 @@ class OpenSSLHash {
     }
     check_out_size_throw(size, out);
   }
     }
     check_out_size_throw(size, out);
   }
-  static void check_out_size_throw(size_t size, MutableByteRange out);
+  [[noreturn]] static void check_out_size_throw(
+      size_t size,
+      MutableByteRange out);
 
   static inline void check_libssl_result(int expected, int result) {
     if (LIKELY(result == expected)) {
 
   static inline void check_libssl_result(int expected, int result) {
     if (LIKELY(result == expected)) {
@@ -181,8 +183,7 @@ class OpenSSLHash {
     }
     check_libssl_result_throw();
   }
     }
     check_libssl_result_throw();
   }
-  static void check_libssl_result_throw();
-
+  [[noreturn]] static void check_libssl_result_throw();
 };
 
 }
 };
 
 }
index 0cb59b96c5ac906f5e64fcbd4ce73201ad1921e4..f2015ce7c249ff850ca0c3c72789007db6c693cb 100644 (file)
@@ -23,7 +23,7 @@
 
 using namespace folly;
 
 
 using namespace folly;
 
-void fail() {
+[[noreturn]] void fail() {
   FOLLY_SAFE_CHECK(0 + 0, "hello");
 }
 
   FOLLY_SAFE_CHECK(0 + 0, "hello");
 }
 
index 892a4352a20b9b3c0ceec7523fae39dade24f979..b3eb981b663b01759dbb774b71583595f227803f 100644 (file)
@@ -295,6 +295,7 @@ TEST(ScopeGuard, TEST_THROWING_CLEANUP_ACTION) {
   struct ThrowingCleanupAction {
     explicit ThrowingCleanupAction(int& scopeExitExecuted)
         : scopeExitExecuted_(scopeExitExecuted) {}
   struct ThrowingCleanupAction {
     explicit ThrowingCleanupAction(int& scopeExitExecuted)
         : scopeExitExecuted_(scopeExitExecuted) {}
+    [[noreturn]]
     ThrowingCleanupAction(const ThrowingCleanupAction& other)
         : scopeExitExecuted_(other.scopeExitExecuted_) {
       throw std::runtime_error("whoa");
     ThrowingCleanupAction(const ThrowingCleanupAction& other)
         : scopeExitExecuted_(other.scopeExitExecuted_) {
       throw std::runtime_error("whoa");
index 68a601d937e55b662c542dceebf7fb536fec3eca..6dfa896e191ec7f0a6352743ff78d9162408ddb3 100644 (file)
@@ -60,7 +60,7 @@ void runChild(const char* file) {
   CHECK_ERR(creat(file, 0600));
 }
 
   CHECK_ERR(creat(file, 0600));
 }
 
-void runParent(const char* file) {
+[[noreturn]] void runParent(const char* file) {
   std::vector<std::string> args {"/proc/self/exe", "--child", file};
   Subprocess proc(
       args,
   std::vector<std::string> args {"/proc/self/exe", "--child", file};
   Subprocess proc(
       args,
index 7da5df99cbc2397193a8a990c8fc71c8b24dfac0..0818b46817e7505a0aeb960ae68d79a2e999e7bf 100644 (file)
@@ -36,6 +36,7 @@ class Exception : public std::exception {
 void doNothing() {
 }
 
 void doNothing() {
 }
 
+[[noreturn]]
 void throwException() {
   throw Exception("this is a test");
 }
 void throwException() {
   throw Exception("this is a test");
 }
index e248aa63b03366626af048422cedcd0169c6e17b..c6d82fe0dc31b4c939d39d9541ea585f5e4d8afa 100644 (file)
@@ -24,7 +24,7 @@
 
 void doNothing();
 
 
 void doNothing();
 
-void throwException();
+[[noreturn]] void throwException();
 std::exception_ptr returnExceptionPtr();
 void exceptionPtrReturnParam(std::exception_ptr* excReturn);
 std::string returnString();
 std::exception_ptr returnExceptionPtr();
 void exceptionPtrReturnParam(std::exception_ptr* excReturn);
 std::string returnString();