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) {
}
// 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");
std::terminate(); // Fail hard, fail fast.
}
// 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
return data_[detail::fixedstring::checkOverflowNothrow(i, size_)];
return data_[detail::fixedstring::checkOverflow(i, size_)];
#endif
}
......@@ -1164,21 +1156,21 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase {
#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]`
*/
FOLLY_CPP14_CONSTEXPR Char& front() noexcept(false) {
FOLLY_CPP14_CONSTEXPR Char& front() noexcept {
return (*this)[0u];
}
/**
* \overload
*/
constexpr const Char& front() const noexcept(false) {
constexpr const Char& front() const noexcept {
return (*this)[0u];
}
......@@ -1186,22 +1178,22 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase {
* \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
return data_[size_ - detail::fixedstring::checkOverflowNothrow(1u, size_)];
return data_[size_ - detail::fixedstring::checkOverflow(1u, size_)];
#endif
}
/**
* \overload
*/
constexpr const Char& back() const noexcept(false) {
constexpr const Char& back() const noexcept {
#ifdef NDEBUG
return data_[size_ - 1u];
#else
return data_[size_ - detail::fixedstring::checkOverflowNothrow(1u, size_)];
return data_[size_ - detail::fixedstring::checkOverflow(1u, size_)];
#endif
}
......
......@@ -24,7 +24,7 @@ namespace folly {
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));
......
......@@ -27,7 +27,7 @@ namespace folly {
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) {
......
......@@ -256,7 +256,7 @@ struct StaticMetaBase {
StaticMetaBase(ThreadEntry* (*threadEntry)(), bool strict);
~StaticMetaBase() {
[[noreturn]] ~StaticMetaBase() {
LOG(FATAL) << "StaticMeta lives forever!";
}
......
......@@ -168,7 +168,7 @@ folly::dynamic DynamicParser::ParserStack::releaseErrors() {
return releaseErrorsImpl();
}
void DynamicParser::ParserStack::throwErrors() {
[[noreturn]] void DynamicParser::ParserStack::throwErrors() {
throw DynamicParserParseError(releaseErrorsImpl());
}
......
......@@ -357,7 +357,7 @@ private:
folly::dynamic releaseErrors();
// Invoked on error when using OnError::THROW.
void throwErrors();
[[noreturn]] void throwErrors();
private:
friend struct Pop;
......
......@@ -20,7 +20,7 @@
#include <folly/experimental/exception_tracer/ExceptionTracer.h>
void bar() {
[[noreturn]] void bar() {
throw std::runtime_error("hello");
}
......@@ -45,7 +45,7 @@ void foo() {
}
}
void baz() {
[[noreturn]] void baz() {
try {
try {
bar();
......
......@@ -26,11 +26,17 @@
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;
......
......@@ -118,7 +118,7 @@ void Fiber::recordStackPosition() {
VLOG(4) << "Stack usage: " << currentPosition;
}
void Fiber::fiberFunc() {
[[noreturn]] void Fiber::fiberFunc() {
#ifdef FOLLY_SANITIZE_ADDRESS
fiberManager_.registerFinishSwitchStackWithAsan(
nullptr, &asanMainStackBase_, &asanMainStackSize_);
......
......@@ -90,7 +90,7 @@ class Fiber {
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,
......
......@@ -21,12 +21,14 @@
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()));
}
void OpenSSLHash::check_libssl_result_throw() {
[[noreturn]] void OpenSSLHash::check_libssl_result_throw() {
throw std::runtime_error("openssl crypto function failed");
}
......
......@@ -173,7 +173,9 @@ class OpenSSLHash {
}
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)) {
......@@ -181,8 +183,7 @@ class OpenSSLHash {
}
check_libssl_result_throw();
}
static void check_libssl_result_throw();
[[noreturn]] static void check_libssl_result_throw();
};
}
......
......@@ -23,7 +23,7 @@
using namespace folly;
void fail() {
[[noreturn]] void fail() {
FOLLY_SAFE_CHECK(0 + 0, "hello");
}
......
......@@ -295,6 +295,7 @@ TEST(ScopeGuard, TEST_THROWING_CLEANUP_ACTION) {
struct ThrowingCleanupAction {
explicit ThrowingCleanupAction(int& scopeExitExecuted)
: scopeExitExecuted_(scopeExitExecuted) {}
[[noreturn]]
ThrowingCleanupAction(const ThrowingCleanupAction& other)
: scopeExitExecuted_(other.scopeExitExecuted_) {
throw std::runtime_error("whoa");
......
......@@ -60,7 +60,7 @@ void runChild(const char* file) {
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,
......
......@@ -36,6 +36,7 @@ class Exception : public std::exception {
void doNothing() {
}
[[noreturn]]
void throwException() {
throw Exception("this is a test");
}
......
......@@ -24,7 +24,7 @@
void doNothing();
void throwException();
[[noreturn]] void throwException();
std::exception_ptr returnExceptionPtr();
void exceptionPtrReturnParam(std::exception_ptr* excReturn);
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