MSVC translation of noreturn attribute
authorElizabeth Smith <elizabeths@fb.com>
Wed, 16 Apr 2014 20:49:35 +0000 (13:49 -0700)
committerSara Golemon <sgolemon@fb.com>
Fri, 18 Apr 2014 19:04:15 +0000 (12:04 -0700)
Summary:
Provide translations for gcc noreturn attribute

__attribute__((noreturn)) is gcc specific, clang understands it on nix systems, but for msvc __declspec(noreturn) is the compiler specific version, which clang will imitate/use on windows.  There was already a FOLLY_NORETURN in portability.h, however because of __declspec limitations it must prefix the declaration, not postfix.  The gcc noreturn attribute does not have this limitation and will work prefixed OR postfixed, so to keep from turning code into spaghetti nonsense, the macro was moved to the front of declations where it is currently used.  This will allow it to work with the proper definitions on clang, clang on windows, gcc, and msvc

Test Plan: fbmake runtests

Reviewed By: delong.j@fb.com

FB internal diff: D1279466

folly/Exception.h
folly/Format.h
folly/FormatArg.h
folly/Portability.h
folly/SafeAssert.h
folly/Subprocess.cpp
folly/detail/FunctionalExcept.h
folly/experimental/exception_tracer/ExceptionTracerLib.cpp
folly/experimental/io/HugePageUtil.cpp

index 7c0665c781df6bc43142130fc4543a20c25120bf..cfa265d8ac41401e34fbc029f25dd13cc7a18872 100644 (file)
@@ -37,13 +37,13 @@ namespace folly {
 // The *Explicit functions take an explicit value for errno.
 
 // Helper to throw std::system_error
-void throwSystemErrorExplicit(int err, const char*) FOLLY_NORETURN;
+FOLLY_NORETURN void throwSystemErrorExplicit(int err, const char*);
 inline void throwSystemErrorExplicit(int err, const char* msg) {
   throw std::system_error(err, std::system_category(), msg);
 }
 
 template <class... Args>
-void throwSystemErrorExplicit(int, Args&&... args) FOLLY_NORETURN;
+FOLLY_NORETURN void throwSystemErrorExplicit(int, Args&&... args);
 template <class... Args>
 void throwSystemErrorExplicit(int err, Args&&... args) {
   throwSystemErrorExplicit(
@@ -52,7 +52,7 @@ void throwSystemErrorExplicit(int err, Args&&... args) {
 
 // Helper to throw std::system_error from errno and components of a string
 template <class... Args>
-void throwSystemError(Args&&... args) FOLLY_NORETURN;
+FOLLY_NORETURN void throwSystemError(Args&&... args);
 template <class... Args>
 void throwSystemError(Args&&... args) {
   throwSystemErrorExplicit(errno, std::forward<Args>(args)...);
index bccdf86d3fcae3680c2a48c90f06895d86cc01c8..970ca405cd28dbc4247fd19dc4d3c5faa9a15c98 100644 (file)
@@ -128,7 +128,7 @@ class Formatter {
       typename std::decay<Args>::type>...> ValueTuple;
   static constexpr size_t valueCount = std::tuple_size<ValueTuple>::value;
 
-  void handleFormatStrError() const FOLLY_NORETURN;
+  FOLLY_NORETURN void handleFormatStrError() const;
   template <class Output>
   void appendOutput(Output& out) const;
 
index 48bfe2af8bb2061312b4fc488e4ef289e5b9c943..fda872d39a901e16c3a68849299b8d21c45f2e7f 100644 (file)
@@ -80,7 +80,7 @@ struct FormatArg {
   template <typename... Args>
   std::string errorStr(Args&&... args) const;
   template <typename... Args>
-  void error(Args&&... args) const FOLLY_NORETURN;
+  FOLLY_NORETURN void error(Args&&... args) const;
 
   /**
    * Full argument string, as passed in to the constructor.
index d7ef09bdf7f45ee11c143f987a05d53bea9cc14a..0a8989af3e4c3f002c4461b3ac20b27597a5f9fd 100644 (file)
@@ -42,9 +42,13 @@ struct MaxAlign { char c; } __attribute__((aligned));
 # error Cannot define MaxAlign on this platform
 #endif
 
+// compiler specific attribute translation
+// msvc should come first, so if clang is in msvc mode it gets the right defines
 
 // noreturn
-#if defined(__clang__) || defined(__GNUC__)
+#if defined(_MSC_VER)
+# define FOLLY_NORETURN __declspec(noreturn)
+#elif defined(__clang__) || defined(__GNUC__)
 # define FOLLY_NORETURN __attribute__((noreturn))
 #else
 # define FOLLY_NORETURN
index 2c173d6c6fdcb187d9cc85efa07eed968e6007a8..1bac6c77d9dd258db0aac9ad513d7c056f1a1c93 100644 (file)
@@ -43,9 +43,9 @@
 
 namespace folly { namespace detail {
 
-void assertionFailure(const char* expr, const char* msg, const char* file,
-                      unsigned int line, const char* function)
-  FOLLY_NORETURN;
+FOLLY_NORETURN void assertionFailure(const char* expr, const char* msg,
+                      const char* file, unsigned int line,
+                      const char* function);
 
 }}  // namespace folly
 
index c03a5b29200651fc1401dfd367b09eaf765f9334..ac1fc8e40f6f24c490bc2a8db443233041f892ce 100644 (file)
@@ -197,7 +197,7 @@ struct ChildErrorInfo {
   int errnoValue;
 };
 
-void childError(int errFd, int errCode, int errnoValue) FOLLY_NORETURN;
+FOLLY_NORETURN void childError(int errFd, int errCode, int errnoValue);
 void childError(int errFd, int errCode, int errnoValue) {
   ChildErrorInfo info = {errCode, errnoValue};
   // Write the error information over the pipe to our parent process.
index a1aa586cf79ec44c2003b769374cadbcf78a1680..1aaecebe323795b897bc4a1c9f5bdd71acdbd540 100644 (file)
@@ -21,9 +21,9 @@
 
 FOLLY_NAMESPACE_STD_BEGIN
 
-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) FOLLY_NORETURN;
+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);
 
 FOLLY_NAMESPACE_STD_END
 
index b04983bc03c106f73467bf700cb1c6d5ce85da6a..8105a1563264fd15cf64bd68517ef70eae31d9de 100644 (file)
 namespace __cxxabiv1 {
 
 extern "C" {
-void __cxa_throw(void* thrownException, std::type_info* type,
-                 void (*destructor)(void)) FOLLY_NORETURN;
+FOLLY_NORETURN void __cxa_throw(void* thrownException,
+                 std::type_info* type, void (*destructor)(void));
 void* __cxa_begin_catch(void* excObj);
-void __cxa_rethrow(void) FOLLY_NORETURN;
+FOLLY_NORETURN void __cxa_rethrow(void);
 void __cxa_end_catch(void);
 }
 
@@ -48,11 +48,10 @@ __thread StackTraceStack caughtExceptions;
 pthread_once_t initialized = PTHREAD_ONCE_INIT;
 
 extern "C" {
-typedef void (*CxaThrowType)(void*, std::type_info*, void (*)(void))
-  FOLLY_NORETURN;
+FOLLY_NORETURN typedef void (*CxaThrowType)(void*, std::type_info*,
+                                            void (*)(void));
 typedef void* (*CxaBeginCatchType)(void*);
-typedef void (*CxaRethrowType)(void)
-  FOLLY_NORETURN;
+FOLLY_NORETURN typedef void (*CxaRethrowType)(void);
 typedef void (*CxaEndCatchType)(void);
 
 CxaThrowType orig_cxa_throw;
@@ -61,8 +60,7 @@ CxaRethrowType orig_cxa_rethrow;
 CxaEndCatchType orig_cxa_end_catch;
 }  // extern "C"
 
-typedef void (*RethrowExceptionType)(std::exception_ptr)
-  FOLLY_NORETURN;
+FOLLY_NORETURN typedef void (*RethrowExceptionType)(std::exception_ptr);
 RethrowExceptionType orig_rethrow_exception;
 
 void initialize() {
index 94d03f94f866765d9fe049bd6a593f6d27e63b14..5e687d59baff718e9b626dbd4205b5d9771fa321 100644 (file)
@@ -39,7 +39,7 @@ using namespace folly;
 
 namespace {
 
-void usage(const char* name) FOLLY_NORETURN;
+FOLLY_NORETURN void usage(const char* name);
 
 void usage(const char* name) {
   std::cerr << folly::format(