From 15057af2f9d667a25235f544d434f17c858cb929 Mon Sep 17 00:00:00 2001 From: Kp Date: Mon, 28 Jun 2021 03:37:50 +0000 Subject: [PATCH] Replace __noreturn with C++11 [[noreturn]] This allows non-GNU-C compilers to see the attribute. --- common/include/dxxerror.h | 22 +++++++--------------- common/misc/error.cpp | 8 ++++++-- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/common/include/dxxerror.h b/common/include/dxxerror.h index fe603e73f..dca2e77c8 100644 --- a/common/include/dxxerror.h +++ b/common/include/dxxerror.h @@ -31,14 +31,6 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #include "dsx-ns.h" #include -#ifdef __cplusplus - -#ifdef __GNUC__ -#define __noreturn __attribute__ ((noreturn)) -#else -#define __noreturn -#endif - namespace dcx { void Warning_puts(const char *str) __attribute_nonnull(); @@ -48,26 +40,28 @@ void Warning(const char *fmt,...) __attribute_format_printf(1, 2); //print ou void set_warn_func(void (*f)(const char *s));//specifies the function to call with warning messages void clear_warn_func();//say this function no longer valid #endif -__noreturn __attribute_nonnull() +[[noreturn]] void Error_puts(const char *file, unsigned line, const char *func, const char *str); #define Error_puts(F) Error_puts(__FILE__, __LINE__, __func__, F) -__noreturn __attribute_format_printf(4, 5) __attribute_nonnull() +[[noreturn]] void Error(const char *file, unsigned line, const char *func, const char *fmt,...); //exit with error code=1, print message #define Error(F,...) dxx_call_printf_checked(Error,(Error_puts),(__FILE__, __LINE__, __func__),(F),##__VA_ARGS__) -__noreturn +[[noreturn]] void UserError_puts(const char *str, std::size_t); template -__noreturn +[[noreturn]] static inline void UserError_puts(const char (&str)[len]) { UserError_puts(str, len - 1); } -void UserError(const char *fmt, ...) __noreturn __attribute_format_printf(1, 2); + +[[noreturn]] +void UserError(const char *fmt, ...) __attribute_format_printf(1, 2); } #define DXX_STRINGIZE_FL2(F,L,S) F ":" #L ": " S @@ -129,5 +123,3 @@ static inline void d_debugbreak() } } - -#endif diff --git a/common/misc/error.cpp b/common/misc/error.cpp index 0e876c9f3..26f79ea04 100644 --- a/common/misc/error.cpp +++ b/common/misc/error.cpp @@ -59,13 +59,15 @@ void clear_warn_func() constexpr auto warn_func = &warn_printf; #endif +namespace { + static void print_exit_message(const char *exit_message, size_t len) { con_puts(CON_CRITICAL, exit_message, len); msgbox_error(exit_message); } -__noreturn +[[noreturn]] static void abort_print_exit_message(const char *exit_message, size_t len) { print_exit_message(exit_message, len); @@ -73,13 +75,15 @@ static void abort_print_exit_message(const char *exit_message, size_t len) std::abort(); } -__noreturn +[[noreturn]] static void graceful_print_exit_message(const char *exit_message, size_t len) { print_exit_message(exit_message, len); exit(1); } +} + void (Error_puts)(const char *filename, const unsigned line, const char *func, const char *str) { char exit_message[MAX_MSG_LEN]; // don't put the new line in for dialog output