}
// 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
#ifdef NDEBUG
return data_[i];
#else
- return data_[detail::fixedstring::checkOverflowNothrow(i, size_)];
+ return data_[detail::fixedstring::checkOverflow(i, size_)];
#endif
}
#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];
}
* \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
}
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));
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) {
StaticMetaBase(ThreadEntry* (*threadEntry)(), bool strict);
- ~StaticMetaBase() {
+ [[noreturn]] ~StaticMetaBase() {
LOG(FATAL) << "StaticMeta lives forever!";
}
return releaseErrorsImpl();
}
-void DynamicParser::ParserStack::throwErrors() {
+[[noreturn]] void DynamicParser::ParserStack::throwErrors() {
throw DynamicParserParseError(releaseErrorsImpl());
}
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()
#include <folly/experimental/exception_tracer/ExceptionTracer.h>
-void bar() {
+[[noreturn]] void bar() {
throw std::runtime_error("hello");
}
}
}
-void baz() {
+[[noreturn]] void baz() {
try {
try {
bar();
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;
VLOG(4) << "Stack usage: " << currentPosition;
}
-void Fiber::fiberFunc() {
+[[noreturn]] void Fiber::fiberFunc() {
#ifdef FOLLY_SANITIZE_ADDRESS
fiberManager_.registerFinishSwitchStackWithAsan(
nullptr, &asanMainStackBase_, &asanMainStackSize_);
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,
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");
}
}
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)) {
}
check_libssl_result_throw();
}
- static void check_libssl_result_throw();
-
+ [[noreturn]] static void check_libssl_result_throw();
};
}
using namespace folly;
-void fail() {
+[[noreturn]] void fail() {
FOLLY_SAFE_CHECK(0 + 0, "hello");
}
struct ThrowingCleanupAction {
explicit ThrowingCleanupAction(int& scopeExitExecuted)
: scopeExitExecuted_(scopeExitExecuted) {}
+ [[noreturn]]
ThrowingCleanupAction(const ThrowingCleanupAction& other)
: scopeExitExecuted_(other.scopeExitExecuted_) {
throw std::runtime_error("whoa");
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,
void doNothing() {
}
+[[noreturn]]
void throwException() {
throw Exception("this is a test");
}
void doNothing();
-void throwException();
+[[noreturn]] void throwException();
std::exception_ptr returnExceptionPtr();
void exceptionPtrReturnParam(std::exception_ptr* excReturn);
std::string returnString();