} else {
throw std::invalid_argument("Unknown address family");
}
- return {IPAddress(0), uint8_t(0)};
}
[[noreturn]] void IPAddress::asV4Throw() const {
#include <glog/logging.h>
+#include <folly/Assume.h>
#include <folly/Conv.h>
#include <folly/Exception.h>
#include <folly/ScopeGuard.h>
return to<std::string>("killed by signal ", killSignal(),
(coreDumped() ? " (core dumped)" : ""));
}
- CHECK(false); // unreached
- return ""; // silence GCC warning
+ assume_unreachable();
}
CalledProcessError::CalledProcessError(ProcessReturnCode rc)
int main() {
folly::symbolizer::installFatalSignalHandler();
__builtin_trap();
- return 0;
}
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;
});
}
// 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));
// 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());
}
// 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);
}
// 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);
// exception_wrapper, return T
{
auto f = makeFuture()
- .then([] {
+ .then([]() -> int {
throw eggs;
- return 0;
})
.onError([&](exception_wrapper /* e */) {
flag();
// 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);
// 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_) {
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);
}
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);
TEST(Try, makeTryWithVoidThrow) {
auto func = []() {
throw std::runtime_error("Runtime");
- return;
};
auto result = makeTryWith(func);