Use C++'s standardized [[noreturn]] attribute
authorYedidya Feldblum <yfeldblum@fb.com>
Wed, 23 Mar 2016 19:19:45 +0000 (12:19 -0700)
committerFacebook Github Bot 2 <facebook-github-bot-2-bot@fb.com>
Wed, 23 Mar 2016 19:20:24 +0000 (12:20 -0700)
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

folly/Exception.h
folly/FormatArg.h
folly/Indestructible.h
folly/Portability.h
folly/SafeAssert.h
folly/Subprocess.cpp
folly/detail/FunctionalExcept.h
folly/experimental/bser/Load.cpp
folly/experimental/exception_tracer/ExceptionTracerLib.cpp
folly/experimental/io/HugePageUtil.cpp
folly/experimental/test/NestedCommandLineAppExample.cpp

index d15dcca19e245ffaf35246e9c62956f6a720cce3..30444b2bdaa193f17a0eb6764b20294cb95b45f4 100644 (file)
@@ -37,24 +37,19 @@ namespace folly {
 // The *Explicit functions take an explicit value for errno.
 
 // Helper to throw std::system_error
-FOLLY_NORETURN void throwSystemErrorExplicit(int err, const char*);
-inline void throwSystemErrorExplicit(int err, const char* msg) {
+[[noreturn]] inline void throwSystemErrorExplicit(int err, const char* msg) {
   throw std::system_error(err, std::system_category(), msg);
 }
 
 template <class... Args>
-FOLLY_NORETURN void throwSystemErrorExplicit(int, Args&&... args);
-template <class... Args>
-void throwSystemErrorExplicit(int err, Args&&... args) {
+[[noreturn]] void throwSystemErrorExplicit(int err, Args&&... args) {
   throwSystemErrorExplicit(
       err, to<fbstring>(std::forward<Args>(args)...).c_str());
 }
 
 // Helper to throw std::system_error from errno and components of a string
 template <class... Args>
-FOLLY_NORETURN void throwSystemError(Args&&... args);
-template <class... Args>
-void throwSystemError(Args&&... args) {
+[[noreturn]] void throwSystemError(Args&&... args) {
   throwSystemErrorExplicit(errno, std::forward<Args>(args)...);
 }
 
index 8ea863be6dce6294b58d47d861966af86f352cb6..127745c47e16998faea7c5d639cf37c342d0cb8b 100644 (file)
@@ -82,7 +82,7 @@ struct FormatArg {
   template <typename... Args>
   std::string errorStr(Args&&... args) const;
   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.
index 4e01ab8679763a51285b664b20c63e483ce43e26..39c8f151d1201428f9e2ecb8388c4d6ce8c204bf 100644 (file)
@@ -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";
   }
 
index 1da837e883c9b1df6a6ee6a6591197e53ec78e84..efef0184ae5f42bfa37761b7da124e5b9029e19d 100644 (file)
@@ -79,15 +79,6 @@ constexpr bool kHasUnalignedAccess = false;
 # define FOLLY_DEPRECATED(msg)
 #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
 #ifdef _MSC_VER
 # define FOLLY_NOINLINE __declspec(noinline)
index 804c2c9db39eefba7667d26b10ac20d76ac6dae8..65d2e9f9df3af809971a4ce15683a647c44f00d7 100644 (file)
 
 namespace folly { namespace detail {
 
-FOLLY_NORETURN void assertionFailure(const char* expr, const char* msg,
-                      const char* file, unsigned int line,
-                      const char* function);
-
+[[noreturn]] void assertionFailure(
+    const char* expr,
+    const char* msg,
+    const char* file,
+    unsigned int line,
+    const char* function);
 }}  // namespace folly
 
 #endif /* FOLLY_SAFEASSERT_H_ */
index c40630a5f7f59dace01854336f4e9bc78cd5e8c9..769cbebb5f51c184106a24836fff35f3e263c37c 100644 (file)
@@ -210,8 +210,7 @@ struct ChildErrorInfo {
   int errnoValue;
 };
 
-FOLLY_NORETURN void childError(int errFd, int errCode, int errnoValue);
-void childError(int errFd, int errCode, int errnoValue) {
+[[noreturn]] void childError(int errFd, int errCode, int errnoValue) {
   ChildErrorInfo info = {errCode, errnoValue};
   // Write the error information over the pipe to our parent process.
   // We can't really do anything else if this write call fails.
index b0018779d7dd34b79d4b5cd39bc907755983671b..575da6f3472d9713ddb46074f0d61b595920afcd 100644 (file)
 
 FOLLY_NAMESPACE_STD_BEGIN
 
-FOLLY_NORETURN void __throw_length_error(const char* msg);
-FOLLY_NORETURN void __throw_logic_error(const char* msg);
-FOLLY_NORETURN void __throw_out_of_range(const char* msg);
+[[noreturn]] void __throw_length_error(const char* msg);
+[[noreturn]] void __throw_logic_error(const char* msg);
+[[noreturn]] void __throw_out_of_range(const char* msg);
 
 #ifdef _MSC_VER
-FOLLY_NORETURN void __throw_bad_alloc();
+[[noreturn]] void __throw_bad_alloc();
 #endif
 
 FOLLY_NAMESPACE_STD_END
index 874037b4f44b16d85a2cfead0dbef7a9eb33569d..9898de8aeacc8fabba287d49c5ba1ae74c0e94d0 100644 (file)
@@ -25,7 +25,7 @@ namespace bser {
 static dynamic parseBser(Cursor& curs);
 
 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)...,
                                                " with ",
                                                curs.length(),
index d0ac4baa86509e6243ff73f5ffef8221a4cb2036..2d2c0133f6cb1239b160920dd9844651dc04fd09 100644 (file)
 namespace __cxxabiv1 {
 
 extern "C" {
-FOLLY_NORETURN void __cxa_throw(void* thrownException,
-                                std::type_info* type,
-                                void (*destructor)(void*));
+void __cxa_throw(
+    void* thrownException,
+    std::type_info* type,
+    void (*destructor)(void*)) __attribute__((__noreturn__));
 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_end_catch(void);
 }
index 8f58ad39b1b6a80fde4bd65809f82c41b74dcad1..d3ba4b5245eac37217f23f396114e4013dc067d4 100644 (file)
@@ -41,9 +41,7 @@ using namespace folly;
 
 namespace {
 
-FOLLY_NORETURN void usage(const char* name);
-
-void usage(const char* name) {
+[[noreturn]] void usage(const char* name) {
   std::cerr << folly::format(
       "Usage: {0}\n"
       "         list all huge page sizes and their mount points\n"
index 6dfa2c2b8ffdb96a5f85834810912be21beffa59..a07dfa9d650ac3a6e4b0aacb5993066b5b5e57be 100644 (file)
@@ -55,11 +55,11 @@ class Concatenator {
   size_t lineNumber_ = 0;
 };
 
-FOLLY_NORETURN void throwOutputError() {
+[[noreturn]] void throwOutputError() {
   throw OutputError(folly::errnoStr(errno).toStdString());
 }
 
-FOLLY_NORETURN void throwInputError() {
+[[noreturn]] void throwInputError() {
   throw InputError(folly::errnoStr(errno).toStdString());
 }