From 641256ea22a5bdd4f66a57c5e68c8d89882dfc5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Wed, 14 Sep 2022 01:59:24 +0200 Subject: [PATCH] gmacros: Prioritize the usage of [[noreturn]] in C++11 We defined G_NO_RETURN as [[noreturn]] in the C++ case, but only after trying the __attribute__ syntax, so it was never used in GNUC compatible compilers. Give it priority instead when supporting a C++11 compiler and onwards. As per this we need to adapt the code in the places where it was not properly used (leading to compilation warnings). --- glib/gmacros.h | 8 ++++---- glib/gmessages.h | 4 ++-- glib/gtestutils.h | 2 +- glib/gutils.h | 3 +-- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/glib/gmacros.h b/glib/gmacros.h index 0ca9a70d0..7355a0d0c 100644 --- a/glib/gmacros.h +++ b/glib/gmacros.h @@ -1053,16 +1053,16 @@ * evaluated when a header is included. This results in warnings in third party * code which includes glib.h, even if the third party code doesn’t use the new * macro itself. */ -#if g_macro__has_attribute(__noreturn__) +#if G_CXX_STD_CHECK_VERSION (11) + /* Use ISO C++11 syntax when the compiler supports it. */ +# define G_NORETURN [[noreturn]] +#elif g_macro__has_attribute(__noreturn__) /* For compatibility with G_NORETURN_FUNCPTR on clang, use __attribute__((__noreturn__)), not _Noreturn. */ # define G_NORETURN __attribute__ ((__noreturn__)) #elif defined (_MSC_VER) && (1200 <= _MSC_VER) /* Use MSVC specific syntax. */ # define G_NORETURN __declspec (noreturn) - /* Use ISO C++11 syntax when the compiler supports it. */ -#elif G_CXX_STD_CHECK_VERSION (11) -# define G_NORETURN [[noreturn]] /* Use ISO C11 syntax when the compiler supports it. */ #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 201112 # define G_NORETURN _Noreturn diff --git a/glib/gmessages.h b/glib/gmessages.h index 119b72e91..eab6d0678 100644 --- a/glib/gmessages.h +++ b/glib/gmessages.h @@ -291,8 +291,8 @@ void g_warn_message (const char *domain, int line, const char *func, const char *warnexpr) G_ANALYZER_NORETURN; -GLIB_DEPRECATED G_NORETURN +GLIB_DEPRECATED void g_assert_warning (const char *log_domain, const char *file, const int line, @@ -409,7 +409,7 @@ void g_log_structured_standard (const gchar *log_domain, format) #endif #else /* no varargs macros */ -static G_NORETURN void g_error (const gchar *format, ...) G_ANALYZER_NORETURN; +G_NORETURN static void g_error (const gchar *format, ...) G_ANALYZER_NORETURN; static void g_critical (const gchar *format, ...) G_ANALYZER_NORETURN; static inline void diff --git a/glib/gtestutils.h b/glib/gtestutils.h index bc404d96d..5db453a70 100644 --- a/glib/gtestutils.h +++ b/glib/gtestutils.h @@ -541,8 +541,8 @@ void g_assertion_message (const char *domain, int line, const char *func, const char *message) G_ANALYZER_NORETURN; -GLIB_AVAILABLE_IN_ALL G_NORETURN +GLIB_AVAILABLE_IN_ALL void g_assertion_message_expr (const char *domain, const char *file, int line, diff --git a/glib/gutils.h b/glib/gutils.h index 36e2b50f5..efc691449 100644 --- a/glib/gutils.h +++ b/glib/gutils.h @@ -426,8 +426,7 @@ g_bit_storage_impl (gulong number) # include # define g_abort() abort () #else -GLIB_AVAILABLE_IN_2_50 -G_NORETURN void g_abort (void) G_ANALYZER_NORETURN; +G_NORETURN GLIB_AVAILABLE_IN_2_50 void g_abort (void) G_ANALYZER_NORETURN; #endif #endif