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

Allow building with -Wmissing-noreturn

Summary: If your function doesn't return you should be explicit about it.

Reviewed By: meyering

Differential Revision: D4309893

fbshipit-source-id: ce275ec8f42e2cb3253a1e40e263934649f09d9e
parent f2203c94
...@@ -102,19 +102,11 @@ constexpr std::size_t checkOverflowOrNpos(std::size_t i, std::size_t max) { ...@@ -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() { [[noreturn]] inline void assertNotNullTerminated() noexcept {
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 {
assert( assert(
false && false &&
"Non-null terminated string used to initialize a BasicFixedString"); "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 { ...@@ -1153,7 +1145,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase {
#ifdef NDEBUG #ifdef NDEBUG
return data_[i]; return data_[i];
#else #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 { ...@@ -1164,21 +1156,21 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase {
#ifdef NDEBUG #ifdef NDEBUG
return data_[i]; return data_[i];
#else #else
return data_[detail::fixedstring::checkOverflowNothrow(i, size_)]; return data_[detail::fixedstring::checkOverflow(i, size_)];
#endif #endif
} }
/** /**
* \note Equivalent to `(*this)[0]` * \note Equivalent to `(*this)[0]`
*/ */
FOLLY_CPP14_CONSTEXPR Char& front() noexcept(false) { FOLLY_CPP14_CONSTEXPR Char& front() noexcept {
return (*this)[0u]; return (*this)[0u];
} }
/** /**
* \overload * \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 { ...@@ -1186,22 +1178,22 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase {
* \note Equivalent to `at(size()-1)` * \note Equivalent to `at(size()-1)`
* \pre `!empty()` * \pre `!empty()`
*/ */
FOLLY_CPP14_CONSTEXPR Char& back() noexcept(false) { FOLLY_CPP14_CONSTEXPR Char& back() noexcept {
#ifdef NDEBUG #ifdef NDEBUG
return data_[size_ - 1u]; return data_[size_ - 1u];
#else #else
return data_[size_ - detail::fixedstring::checkOverflowNothrow(1u, size_)]; return data_[size_ - detail::fixedstring::checkOverflow(1u, size_)];
#endif #endif
} }
/** /**
* \overload * \overload
*/ */
constexpr const Char& back() const noexcept(false) { constexpr const Char& back() const noexcept {
#ifdef NDEBUG #ifdef NDEBUG
return data_[size_ - 1u]; return data_[size_ - 1u];
#else #else
return data_[size_ - detail::fixedstring::checkOverflowNothrow(1u, size_)]; return data_[size_ - detail::fixedstring::checkOverflow(1u, size_)];
#endif #endif
} }
......
...@@ -24,7 +24,7 @@ namespace folly { ...@@ -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); assert(err != 0);
throw std::runtime_error( throw std::runtime_error(
sformat("mallctl {}: {} ({})", cmd, errnoStr(err), err)); sformat("mallctl {}: {} ({})", cmd, errnoStr(err), err));
......
...@@ -27,7 +27,7 @@ namespace folly { ...@@ -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> template <typename T>
void mallctlHelper(const char* cmd, T* out, T* in) { void mallctlHelper(const char* cmd, T* out, T* in) {
......
...@@ -256,7 +256,7 @@ struct StaticMetaBase { ...@@ -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!";
} }
......
...@@ -168,7 +168,7 @@ folly::dynamic DynamicParser::ParserStack::releaseErrors() { ...@@ -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());
} }
......
...@@ -357,9 +357,9 @@ private: ...@@ -357,9 +357,9 @@ private:
folly::dynamic releaseErrors(); folly::dynamic releaseErrors();
// Invoked on error when using OnError::THROW. // Invoked on error when using OnError::THROW.
void throwErrors(); [[noreturn]] void throwErrors();
private: private:
friend struct Pop; friend struct Pop;
folly::dynamic releaseErrorsImpl(); // for releaseErrors() & throwErrors() folly::dynamic releaseErrorsImpl(); // for releaseErrors() & throwErrors()
......
...@@ -20,7 +20,7 @@ ...@@ -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() { ...@@ -45,7 +45,7 @@ void foo() {
} }
} }
void baz() { [[noreturn]] void baz() {
try { try {
try { try {
bar(); bar();
......
...@@ -26,11 +26,17 @@ ...@@ -26,11 +26,17 @@
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;
......
...@@ -118,7 +118,7 @@ void Fiber::recordStackPosition() { ...@@ -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 #ifdef FOLLY_SANITIZE_ADDRESS
fiberManager_.registerFinishSwitchStackWithAsan( fiberManager_.registerFinishSwitchStackWithAsan(
nullptr, &asanMainStackBase_, &asanMainStackSize_); nullptr, &asanMainStackBase_, &asanMainStackSize_);
......
...@@ -90,7 +90,7 @@ class Fiber { ...@@ -90,7 +90,7 @@ class Fiber {
template <typename F, typename G> template <typename F, typename G>
void setFunctionFinally(F&& func, G&& finally); 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,
......
...@@ -21,12 +21,14 @@ ...@@ -21,12 +21,14 @@
namespace folly { namespace folly {
namespace ssl { 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( throw std::invalid_argument(folly::sformat(
"expected out of size {} but was of size {}", size, out.size())); "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");
} }
......
...@@ -173,7 +173,9 @@ class OpenSSLHash { ...@@ -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) { static inline void check_libssl_result(int expected, int result) {
if (LIKELY(result == expected)) { if (LIKELY(result == expected)) {
...@@ -181,8 +183,7 @@ class OpenSSLHash { ...@@ -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();
}; };
} }
......
...@@ -23,7 +23,7 @@ ...@@ -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");
} }
......
...@@ -295,6 +295,7 @@ TEST(ScopeGuard, TEST_THROWING_CLEANUP_ACTION) { ...@@ -295,6 +295,7 @@ TEST(ScopeGuard, TEST_THROWING_CLEANUP_ACTION) {
struct ThrowingCleanupAction { struct ThrowingCleanupAction {
explicit ThrowingCleanupAction(int& scopeExitExecuted) explicit ThrowingCleanupAction(int& scopeExitExecuted)
: scopeExitExecuted_(scopeExitExecuted) {} : scopeExitExecuted_(scopeExitExecuted) {}
[[noreturn]]
ThrowingCleanupAction(const ThrowingCleanupAction& other) ThrowingCleanupAction(const ThrowingCleanupAction& other)
: scopeExitExecuted_(other.scopeExitExecuted_) { : scopeExitExecuted_(other.scopeExitExecuted_) {
throw std::runtime_error("whoa"); throw std::runtime_error("whoa");
......
...@@ -60,7 +60,7 @@ void runChild(const char* 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}; std::vector<std::string> args {"/proc/self/exe", "--child", file};
Subprocess proc( Subprocess proc(
args, args,
......
...@@ -36,6 +36,7 @@ class Exception : public std::exception { ...@@ -36,6 +36,7 @@ class Exception : public std::exception {
void doNothing() { void doNothing() {
} }
[[noreturn]]
void throwException() { void throwException() {
throw Exception("this is a test"); throw Exception("this is a test");
} }
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
void doNothing(); void doNothing();
void throwException(); [[noreturn]] void throwException();
std::exception_ptr returnExceptionPtr(); std::exception_ptr returnExceptionPtr();
void exceptionPtrReturnParam(std::exception_ptr* excReturn); void exceptionPtrReturnParam(std::exception_ptr* excReturn);
std::string returnString(); std::string returnString();
......
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