Commit 9895ee08 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot 2

Use C++'s standardized [[noreturn]] attribute

Summary:Use C++'s standardized `[[noreturn]]` attribute.

All supported compilers (and some unsupported compilers) also support the standardized syntax.

GCC >= 4.8, Clang >= 3.0, and MSVC >= 2015 have direct support for the C++'s standardized way of writing the attribute.

Clang - http://goo.gl/ftJGVM
GCC 4.8.2 - http://goo.gl/ORCVOD
ICC 13.0.1 - http://goo.gl/I5tn5I
MSVC 2015 - https://msdn.microsoft.com/en-us/library/hh567368.aspx

(Regardling Clang, earlier versions may support it. 3.0 was the earliest Clang version listed at godbolt.com, so that's as far back as I went.)

Therefore, we no longer need to use the compiler-specific syntaxes, or use preprocessor macros with per-compiler definitions:

    __attribute__((__noreturn__))
    __attribute__((noreturn))
    __declspec(noreturn)

Reviewed By: Orvid

Differential Revision: D3073621

fb-gh-sync-id: 32d4771d1bf1974693b8574fa2d39c9559872945
shipit-source-id: 32d4771d1bf1974693b8574fa2d39c9559872945
parent dec14727
...@@ -37,24 +37,19 @@ namespace folly { ...@@ -37,24 +37,19 @@ namespace folly {
// The *Explicit functions take an explicit value for errno. // The *Explicit functions take an explicit value for errno.
// Helper to throw std::system_error // Helper to throw std::system_error
FOLLY_NORETURN void throwSystemErrorExplicit(int err, const char*); [[noreturn]] inline void throwSystemErrorExplicit(int err, const char* msg) {
inline void throwSystemErrorExplicit(int err, const char* msg) {
throw std::system_error(err, std::system_category(), msg); throw std::system_error(err, std::system_category(), msg);
} }
template <class... Args> template <class... Args>
FOLLY_NORETURN void throwSystemErrorExplicit(int, Args&&... args); [[noreturn]] void throwSystemErrorExplicit(int err, Args&&... args) {
template <class... Args>
void throwSystemErrorExplicit(int err, Args&&... args) {
throwSystemErrorExplicit( throwSystemErrorExplicit(
err, to<fbstring>(std::forward<Args>(args)...).c_str()); err, to<fbstring>(std::forward<Args>(args)...).c_str());
} }
// Helper to throw std::system_error from errno and components of a string // Helper to throw std::system_error from errno and components of a string
template <class... Args> template <class... Args>
FOLLY_NORETURN void throwSystemError(Args&&... args); [[noreturn]] void throwSystemError(Args&&... args) {
template <class... Args>
void throwSystemError(Args&&... args) {
throwSystemErrorExplicit(errno, std::forward<Args>(args)...); throwSystemErrorExplicit(errno, std::forward<Args>(args)...);
} }
......
...@@ -82,7 +82,7 @@ struct FormatArg { ...@@ -82,7 +82,7 @@ struct FormatArg {
template <typename... Args> template <typename... Args>
std::string errorStr(Args&&... args) const; std::string errorStr(Args&&... args) const;
template <typename... Args> template <typename... Args>
FOLLY_NORETURN void error(Args&&... args) const; [[noreturn]] void error(Args&&... args) const;
/** /**
* Full argument string, as passed in to the constructor. * Full argument string, as passed in to the constructor.
......
...@@ -101,7 +101,7 @@ class Indestructible final { ...@@ -101,7 +101,7 @@ class Indestructible final {
} }
} }
FOLLY_NORETURN FOLLY_NOINLINE static void fail() { [[noreturn]] FOLLY_NOINLINE static void fail() {
LOG(FATAL) << "Indestructible is not initialized"; LOG(FATAL) << "Indestructible is not initialized";
} }
......
...@@ -79,15 +79,6 @@ constexpr bool kHasUnalignedAccess = false; ...@@ -79,15 +79,6 @@ constexpr bool kHasUnalignedAccess = false;
# define FOLLY_DEPRECATED(msg) # define FOLLY_DEPRECATED(msg)
#endif #endif
// noreturn
#if defined(_MSC_VER)
# define FOLLY_NORETURN __declspec(noreturn)
#elif defined(__clang__) || defined(__GNUC__)
# define FOLLY_NORETURN __attribute__((__noreturn__))
#else
# define FOLLY_NORETURN
#endif
// noinline // noinline
#ifdef _MSC_VER #ifdef _MSC_VER
# define FOLLY_NOINLINE __declspec(noinline) # define FOLLY_NOINLINE __declspec(noinline)
......
...@@ -43,10 +43,12 @@ ...@@ -43,10 +43,12 @@
namespace folly { namespace detail { namespace folly { namespace detail {
FOLLY_NORETURN void assertionFailure(const char* expr, const char* msg, [[noreturn]] void assertionFailure(
const char* file, unsigned int line, const char* expr,
const char* function); const char* msg,
const char* file,
unsigned int line,
const char* function);
}} // namespace folly }} // namespace folly
#endif /* FOLLY_SAFEASSERT_H_ */ #endif /* FOLLY_SAFEASSERT_H_ */
...@@ -210,8 +210,7 @@ struct ChildErrorInfo { ...@@ -210,8 +210,7 @@ struct ChildErrorInfo {
int errnoValue; int errnoValue;
}; };
FOLLY_NORETURN void childError(int errFd, int errCode, int errnoValue); [[noreturn]] void childError(int errFd, int errCode, int errnoValue) {
void childError(int errFd, int errCode, int errnoValue) {
ChildErrorInfo info = {errCode, errnoValue}; ChildErrorInfo info = {errCode, errnoValue};
// Write the error information over the pipe to our parent process. // Write the error information over the pipe to our parent process.
// We can't really do anything else if this write call fails. // We can't really do anything else if this write call fails.
......
...@@ -23,12 +23,12 @@ ...@@ -23,12 +23,12 @@
FOLLY_NAMESPACE_STD_BEGIN FOLLY_NAMESPACE_STD_BEGIN
FOLLY_NORETURN void __throw_length_error(const char* msg); [[noreturn]] void __throw_length_error(const char* msg);
FOLLY_NORETURN void __throw_logic_error(const char* msg); [[noreturn]] void __throw_logic_error(const char* msg);
FOLLY_NORETURN void __throw_out_of_range(const char* msg); [[noreturn]] void __throw_out_of_range(const char* msg);
#ifdef _MSC_VER #ifdef _MSC_VER
FOLLY_NORETURN void __throw_bad_alloc(); [[noreturn]] void __throw_bad_alloc();
#endif #endif
FOLLY_NAMESPACE_STD_END FOLLY_NAMESPACE_STD_END
......
...@@ -25,7 +25,7 @@ namespace bser { ...@@ -25,7 +25,7 @@ namespace bser {
static dynamic parseBser(Cursor& curs); static dynamic parseBser(Cursor& curs);
template <typename... ARGS> template <typename... ARGS>
static FOLLY_NORETURN void throwDecodeError(Cursor& curs, ARGS&&... args) { [[noreturn]] static void throwDecodeError(Cursor& curs, ARGS&&... args) {
throw BserDecodeError(folly::to<std::string>(std::forward<ARGS>(args)..., throw BserDecodeError(folly::to<std::string>(std::forward<ARGS>(args)...,
" with ", " with ",
curs.length(), curs.length(),
......
...@@ -27,11 +27,12 @@ ...@@ -27,11 +27,12 @@
namespace __cxxabiv1 { namespace __cxxabiv1 {
extern "C" { extern "C" {
FOLLY_NORETURN void __cxa_throw(void* thrownException, void __cxa_throw(
std::type_info* type, void* thrownException,
void (*destructor)(void*)); std::type_info* type,
void (*destructor)(void*)) __attribute__((__noreturn__));
void* __cxa_begin_catch(void* excObj) throw(); void* __cxa_begin_catch(void* excObj) throw();
FOLLY_NORETURN void __cxa_rethrow(void); void __cxa_rethrow(void) __attribute__((__noreturn__));
void __cxa_rethrow(void); void __cxa_rethrow(void);
void __cxa_end_catch(void); void __cxa_end_catch(void);
} }
......
...@@ -41,9 +41,7 @@ using namespace folly; ...@@ -41,9 +41,7 @@ using namespace folly;
namespace { namespace {
FOLLY_NORETURN void usage(const char* name); [[noreturn]] void usage(const char* name) {
void usage(const char* name) {
std::cerr << folly::format( std::cerr << folly::format(
"Usage: {0}\n" "Usage: {0}\n"
" list all huge page sizes and their mount points\n" " list all huge page sizes and their mount points\n"
......
...@@ -55,11 +55,11 @@ class Concatenator { ...@@ -55,11 +55,11 @@ class Concatenator {
size_t lineNumber_ = 0; size_t lineNumber_ = 0;
}; };
FOLLY_NORETURN void throwOutputError() { [[noreturn]] void throwOutputError() {
throw OutputError(folly::errnoStr(errno).toStdString()); throw OutputError(folly::errnoStr(errno).toStdString());
} }
FOLLY_NORETURN void throwInputError() { [[noreturn]] void throwInputError() {
throw InputError(folly::errnoStr(errno).toStdString()); throw InputError(folly::errnoStr(errno).toStdString());
} }
......
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