Commit 934a0b06 authored by Elizabeth Smith's avatar Elizabeth Smith Committed by Sara Golemon

MSVC translation of noreturn attribute

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
parent 2c2e0f6e
...@@ -37,13 +37,13 @@ namespace folly { ...@@ -37,13 +37,13 @@ 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
void throwSystemErrorExplicit(int err, const char*) FOLLY_NORETURN; FOLLY_NORETURN void throwSystemErrorExplicit(int err, const char*);
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>
void throwSystemErrorExplicit(int, Args&&... args) FOLLY_NORETURN; FOLLY_NORETURN void throwSystemErrorExplicit(int, Args&&... args);
template <class... Args> template <class... Args>
void throwSystemErrorExplicit(int err, Args&&... args) { void throwSystemErrorExplicit(int err, Args&&... args) {
throwSystemErrorExplicit( throwSystemErrorExplicit(
...@@ -52,7 +52,7 @@ void throwSystemErrorExplicit(int err, Args&&... args) { ...@@ -52,7 +52,7 @@ void throwSystemErrorExplicit(int err, Args&&... args) {
// 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>
void throwSystemError(Args&&... args) FOLLY_NORETURN; FOLLY_NORETURN void throwSystemError(Args&&... args);
template <class... Args> template <class... Args>
void throwSystemError(Args&&... args) { void throwSystemError(Args&&... args) {
throwSystemErrorExplicit(errno, std::forward<Args>(args)...); throwSystemErrorExplicit(errno, std::forward<Args>(args)...);
......
...@@ -128,7 +128,7 @@ class Formatter { ...@@ -128,7 +128,7 @@ class Formatter {
typename std::decay<Args>::type>...> ValueTuple; typename std::decay<Args>::type>...> ValueTuple;
static constexpr size_t valueCount = std::tuple_size<ValueTuple>::value; static constexpr size_t valueCount = std::tuple_size<ValueTuple>::value;
void handleFormatStrError() const FOLLY_NORETURN; FOLLY_NORETURN void handleFormatStrError() const;
template <class Output> template <class Output>
void appendOutput(Output& out) const; void appendOutput(Output& out) const;
......
...@@ -80,7 +80,7 @@ struct FormatArg { ...@@ -80,7 +80,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>
void error(Args&&... args) const FOLLY_NORETURN; FOLLY_NORETURN void error(Args&&... args) const;
/** /**
* Full argument string, as passed in to the constructor. * Full argument string, as passed in to the constructor.
......
...@@ -42,9 +42,13 @@ struct MaxAlign { char c; } __attribute__((aligned)); ...@@ -42,9 +42,13 @@ struct MaxAlign { char c; } __attribute__((aligned));
# error Cannot define MaxAlign on this platform # error Cannot define MaxAlign on this platform
#endif #endif
// compiler specific attribute translation
// msvc should come first, so if clang is in msvc mode it gets the right defines
// noreturn // 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)) # define FOLLY_NORETURN __attribute__((noreturn))
#else #else
# define FOLLY_NORETURN # define FOLLY_NORETURN
......
...@@ -43,9 +43,9 @@ ...@@ -43,9 +43,9 @@
namespace folly { namespace detail { namespace folly { namespace detail {
void assertionFailure(const char* expr, const char* msg, const char* file, FOLLY_NORETURN void assertionFailure(const char* expr, const char* msg,
unsigned int line, const char* function) const char* file, unsigned int line,
FOLLY_NORETURN; const char* function);
}} // namespace folly }} // namespace folly
......
...@@ -197,7 +197,7 @@ struct ChildErrorInfo { ...@@ -197,7 +197,7 @@ struct ChildErrorInfo {
int errnoValue; 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) { 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.
......
...@@ -21,9 +21,9 @@ ...@@ -21,9 +21,9 @@
FOLLY_NAMESPACE_STD_BEGIN FOLLY_NAMESPACE_STD_BEGIN
void __throw_length_error(const char* msg) FOLLY_NORETURN; FOLLY_NORETURN void __throw_length_error(const char* msg);
void __throw_logic_error(const char* msg) FOLLY_NORETURN; FOLLY_NORETURN void __throw_logic_error(const char* msg);
void __throw_out_of_range(const char* msg) FOLLY_NORETURN; FOLLY_NORETURN void __throw_out_of_range(const char* msg);
FOLLY_NAMESPACE_STD_END FOLLY_NAMESPACE_STD_END
......
...@@ -29,10 +29,10 @@ ...@@ -29,10 +29,10 @@
namespace __cxxabiv1 { namespace __cxxabiv1 {
extern "C" { extern "C" {
void __cxa_throw(void* thrownException, std::type_info* type, FOLLY_NORETURN void __cxa_throw(void* thrownException,
void (*destructor)(void)) FOLLY_NORETURN; std::type_info* type, void (*destructor)(void));
void* __cxa_begin_catch(void* excObj); void* __cxa_begin_catch(void* excObj);
void __cxa_rethrow(void) FOLLY_NORETURN; FOLLY_NORETURN void __cxa_rethrow(void);
void __cxa_end_catch(void); void __cxa_end_catch(void);
} }
...@@ -48,11 +48,10 @@ __thread StackTraceStack caughtExceptions; ...@@ -48,11 +48,10 @@ __thread StackTraceStack caughtExceptions;
pthread_once_t initialized = PTHREAD_ONCE_INIT; pthread_once_t initialized = PTHREAD_ONCE_INIT;
extern "C" { extern "C" {
typedef void (*CxaThrowType)(void*, std::type_info*, void (*)(void)) FOLLY_NORETURN typedef void (*CxaThrowType)(void*, std::type_info*,
FOLLY_NORETURN; void (*)(void));
typedef void* (*CxaBeginCatchType)(void*); typedef void* (*CxaBeginCatchType)(void*);
typedef void (*CxaRethrowType)(void) FOLLY_NORETURN typedef void (*CxaRethrowType)(void);
FOLLY_NORETURN;
typedef void (*CxaEndCatchType)(void); typedef void (*CxaEndCatchType)(void);
CxaThrowType orig_cxa_throw; CxaThrowType orig_cxa_throw;
...@@ -61,8 +60,7 @@ CxaRethrowType orig_cxa_rethrow; ...@@ -61,8 +60,7 @@ CxaRethrowType orig_cxa_rethrow;
CxaEndCatchType orig_cxa_end_catch; CxaEndCatchType orig_cxa_end_catch;
} // extern "C" } // extern "C"
typedef void (*RethrowExceptionType)(std::exception_ptr) FOLLY_NORETURN typedef void (*RethrowExceptionType)(std::exception_ptr);
FOLLY_NORETURN;
RethrowExceptionType orig_rethrow_exception; RethrowExceptionType orig_rethrow_exception;
void initialize() { void initialize() {
......
...@@ -39,7 +39,7 @@ using namespace folly; ...@@ -39,7 +39,7 @@ using namespace folly;
namespace { namespace {
void usage(const char* name) FOLLY_NORETURN; FOLLY_NORETURN void usage(const char* name);
void usage(const char* name) { void usage(const char* name) {
std::cerr << folly::format( std::cerr << folly::format(
......
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