mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-28 16:36:14 +01:00
Merge branch 'mark_g_assert_as_noreturn_on_MSVC' into 'master'
Adding macros G_NORETURN and G_NORETURN_FUNCPTR Closes #994 See merge request GNOME/glib!1078
This commit is contained in:
commit
3088fbae52
@ -469,6 +469,8 @@ G_ALIGNOF
|
|||||||
|
|
||||||
<SUBSECTION>
|
<SUBSECTION>
|
||||||
G_CONST_RETURN
|
G_CONST_RETURN
|
||||||
|
G_NORETURN
|
||||||
|
G_NORETURN_FUNCPTR
|
||||||
|
|
||||||
<SUBSECTION>
|
<SUBSECTION>
|
||||||
G_N_ELEMENTS
|
G_N_ELEMENTS
|
||||||
|
@ -37,7 +37,7 @@ static const gchar *info = NULL;
|
|||||||
static GCancellable *cancellable = NULL;
|
static GCancellable *cancellable = NULL;
|
||||||
static gint return_value = 0;
|
static gint return_value = 0;
|
||||||
|
|
||||||
static void G_GNUC_NORETURN
|
static G_NORETURN void
|
||||||
usage (void)
|
usage (void)
|
||||||
{
|
{
|
||||||
fprintf (stderr, "Usage: proxy [-s] (uri|host:port|ip:port|path|srv/protocol/domain)\n");
|
fprintf (stderr, "Usage: proxy [-s] (uri|host:port|ip:port|path|srv/protocol/domain)\n");
|
||||||
|
@ -40,7 +40,7 @@ static gboolean synchronous = FALSE;
|
|||||||
static guint connectable_count = 0;
|
static guint connectable_count = 0;
|
||||||
static GResolverRecordType record_type = 0;
|
static GResolverRecordType record_type = 0;
|
||||||
|
|
||||||
static void G_GNUC_NORETURN
|
static G_NORETURN void
|
||||||
usage (void)
|
usage (void)
|
||||||
{
|
{
|
||||||
fprintf (stderr, "Usage: resolver [-s] [hostname | IP | service/protocol/domain ] ...\n");
|
fprintf (stderr, "Usage: resolver [-s] [hostname | IP | service/protocol/domain ] ...\n");
|
||||||
|
@ -423,6 +423,12 @@
|
|||||||
* It is used for declaring functions which never return. It enables
|
* It is used for declaring functions which never return. It enables
|
||||||
* optimization of the function, and avoids possible compiler warnings.
|
* optimization of the function, and avoids possible compiler warnings.
|
||||||
*
|
*
|
||||||
|
* Since 2.68, it is recommended that code uses %G_NORETURN instead of
|
||||||
|
* %G_GNUC_NORETURN, as that works on more platforms and compilers (in
|
||||||
|
* particular, MSVC and C++11) than %G_GNUC_NORETURN, which works with GCC and
|
||||||
|
* Clang only. %G_GNUC_NORETURN continues to work, so has not been deprecated
|
||||||
|
* yet.
|
||||||
|
*
|
||||||
* Place the attribute after the declaration, just before the semicolon.
|
* Place the attribute after the declaration, just before the semicolon.
|
||||||
*
|
*
|
||||||
* |[<!-- language="C" -->
|
* |[<!-- language="C" -->
|
||||||
@ -917,6 +923,76 @@
|
|||||||
#define G_CONST_RETURN const GLIB_DEPRECATED_MACRO_IN_2_30_FOR(const)
|
#define G_CONST_RETURN const GLIB_DEPRECATED_MACRO_IN_2_30_FOR(const)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* G_NORETURN:
|
||||||
|
*
|
||||||
|
* Expands to the GNU C or MSVC `noreturn` function attribute depending on
|
||||||
|
* the compiler. It is used for declaring functions which never return.
|
||||||
|
* Enables optimization of the function, and avoids possible compiler warnings.
|
||||||
|
*
|
||||||
|
* Note that %G_NORETURN supersedes the previous %G_GNUC_NORETURN macro, which
|
||||||
|
* will eventually be deprecated. %G_NORETURN supports more platforms.
|
||||||
|
*
|
||||||
|
* Place the attribute before the function declaration as follows:
|
||||||
|
*
|
||||||
|
* |[<!-- language="C" -->
|
||||||
|
* G_NORETURN void g_abort (void);
|
||||||
|
* ]|
|
||||||
|
*
|
||||||
|
* Since: 2.68
|
||||||
|
*/
|
||||||
|
/* Note: We can’t annotate this with GLIB_AVAILABLE_MACRO_IN_2_68 because it’s
|
||||||
|
* used within the GLib headers in function declarations which are always
|
||||||
|
* 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 (3 <= __GNUC__ || (__GNUC__ == 2 && 8 <= __GNUC_MINOR__)) || (0x5110 <= __SUNPRO_C)
|
||||||
|
/* For compatibility with G_NORETURN_FUNCPTR on clang, use
|
||||||
|
__attribute__((__noreturn__)), not _Noreturn. */
|
||||||
|
# define G_NORETURN __attribute__ ((__noreturn__))
|
||||||
|
#elif 1200 <= _MSC_VER
|
||||||
|
/* Use MSVC specific syntax. */
|
||||||
|
# define G_NORETURN __declspec (noreturn)
|
||||||
|
/* Use ISO C++11 syntax when the compiler supports it. */
|
||||||
|
#elif (__cplusplus >= 201103 && !(__GNUC__ == 4 && __GNUC_MINOR__ == 7)) || (_MSC_VER >= 1900)
|
||||||
|
# define G_NORETURN [[noreturn]]
|
||||||
|
/* Use ISO C11 syntax when the compiler supports it. */
|
||||||
|
#elif __STDC_VERSION__ >= 201112 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7)
|
||||||
|
# define G_NORETURN _Noreturn
|
||||||
|
#else
|
||||||
|
# define G_NORETURN /* empty */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* G_NORETURN_FUNCPTR:
|
||||||
|
*
|
||||||
|
* Expands to the GNU C or MSVC `noreturn` function attribute depending on
|
||||||
|
* the compiler. It is used for declaring function pointers which never return.
|
||||||
|
* Enables optimization of the function, and avoids possible compiler warnings.
|
||||||
|
*
|
||||||
|
* Place the attribute before the function declaration as follows:
|
||||||
|
*
|
||||||
|
* |[<!-- language="C" -->
|
||||||
|
* G_NORETURN_FUNCPTR void (*funcptr) (void);
|
||||||
|
* ]|
|
||||||
|
*
|
||||||
|
* Note that if the function is not a function pointer, you can simply use
|
||||||
|
* the %G_NORETURN macro as follows:
|
||||||
|
*
|
||||||
|
* |[<!-- language="C" -->
|
||||||
|
* G_NORETURN void g_abort (void);
|
||||||
|
* ]|
|
||||||
|
*
|
||||||
|
* Since: 2.68
|
||||||
|
*/
|
||||||
|
#if (3 <= __GNUC__ || (__GNUC__ == 2 && 8 <= __GNUC_MINOR__)) || (0x5110 <= __SUNPRO_C)
|
||||||
|
# define G_NORETURN_FUNCPTR __attribute__ ((__noreturn__)) \
|
||||||
|
GLIB_AVAILABLE_MACRO_IN_2_68
|
||||||
|
#else
|
||||||
|
# define G_NORETURN_FUNCPTR /* empty */ \
|
||||||
|
GLIB_AVAILABLE_MACRO_IN_2_68
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The G_LIKELY and G_UNLIKELY macros let the programmer give hints to
|
* The G_LIKELY and G_UNLIKELY macros let the programmer give hints to
|
||||||
* the compiler about the expected result of an expression. Some compilers
|
* the compiler about the expected result of an expression. Some compilers
|
||||||
|
@ -283,11 +283,12 @@ void g_warn_message (const char *domain,
|
|||||||
const char *func,
|
const char *func,
|
||||||
const char *warnexpr) G_ANALYZER_NORETURN;
|
const char *warnexpr) G_ANALYZER_NORETURN;
|
||||||
GLIB_DEPRECATED
|
GLIB_DEPRECATED
|
||||||
|
G_NORETURN
|
||||||
void g_assert_warning (const char *log_domain,
|
void g_assert_warning (const char *log_domain,
|
||||||
const char *file,
|
const char *file,
|
||||||
const int line,
|
const int line,
|
||||||
const char *pretty_function,
|
const char *pretty_function,
|
||||||
const char *expression) G_GNUC_NORETURN;
|
const char *expression);
|
||||||
|
|
||||||
GLIB_AVAILABLE_IN_2_56
|
GLIB_AVAILABLE_IN_2_56
|
||||||
void g_log_structured_standard (const gchar *log_domain,
|
void g_log_structured_standard (const gchar *log_domain,
|
||||||
@ -399,7 +400,7 @@ void g_log_structured_standard (const gchar *log_domain,
|
|||||||
format)
|
format)
|
||||||
#endif
|
#endif
|
||||||
#else /* no varargs macros */
|
#else /* no varargs macros */
|
||||||
static void g_error (const gchar *format, ...) G_GNUC_NORETURN G_ANALYZER_NORETURN;
|
static G_NORETURN void g_error (const gchar *format, ...) G_ANALYZER_NORETURN;
|
||||||
static void g_critical (const gchar *format, ...) G_ANALYZER_NORETURN;
|
static void g_critical (const gchar *format, ...) G_ANALYZER_NORETURN;
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
|
@ -1091,7 +1091,7 @@ g_option_context_get_help (GOptionContext *context,
|
|||||||
return g_string_free (string, FALSE);
|
return g_string_free (string, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
G_GNUC_NORETURN
|
G_NORETURN
|
||||||
static void
|
static void
|
||||||
print_help (GOptionContext *context,
|
print_help (GOptionContext *context,
|
||||||
gboolean main_help,
|
gboolean main_help,
|
||||||
|
@ -1116,7 +1116,7 @@ write_all (gint fd, gconstpointer vbuf, gsize to_write)
|
|||||||
|
|
||||||
/* This function is called between fork() and exec() and hence must be
|
/* This function is called between fork() and exec() and hence must be
|
||||||
* async-signal-safe (see signal-safety(7)). */
|
* async-signal-safe (see signal-safety(7)). */
|
||||||
G_GNUC_NORETURN
|
G_NORETURN
|
||||||
static void
|
static void
|
||||||
write_err_and_exit (gint fd, gint msg)
|
write_err_and_exit (gint fd, gint msg)
|
||||||
{
|
{
|
||||||
|
@ -514,11 +514,12 @@ void g_assertion_message (const char *domain,
|
|||||||
const char *func,
|
const char *func,
|
||||||
const char *message) G_ANALYZER_NORETURN;
|
const char *message) G_ANALYZER_NORETURN;
|
||||||
GLIB_AVAILABLE_IN_ALL
|
GLIB_AVAILABLE_IN_ALL
|
||||||
|
G_NORETURN
|
||||||
void g_assertion_message_expr (const char *domain,
|
void g_assertion_message_expr (const char *domain,
|
||||||
const char *file,
|
const char *file,
|
||||||
int line,
|
int line,
|
||||||
const char *func,
|
const char *func,
|
||||||
const char *expr) G_GNUC_NORETURN;
|
const char *expr);
|
||||||
GLIB_AVAILABLE_IN_ALL
|
GLIB_AVAILABLE_IN_ALL
|
||||||
void g_assertion_message_cmpstr (const char *domain,
|
void g_assertion_message_cmpstr (const char *domain,
|
||||||
const char *file,
|
const char *file,
|
||||||
|
@ -434,7 +434,7 @@ g_bit_storage_impl (gulong number)
|
|||||||
# define g_abort() abort ()
|
# define g_abort() abort ()
|
||||||
#else
|
#else
|
||||||
GLIB_AVAILABLE_IN_2_50
|
GLIB_AVAILABLE_IN_2_50
|
||||||
void g_abort (void) G_GNUC_NORETURN G_ANALYZER_NORETURN;
|
G_NORETURN void g_abort (void) G_ANALYZER_NORETURN;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -24,6 +24,11 @@
|
|||||||
#pragma warning(disable:4101) /* unreferenced local variable */
|
#pragma warning(disable:4101) /* unreferenced local variable */
|
||||||
#pragma warning(error:4150)
|
#pragma warning(error:4150)
|
||||||
|
|
||||||
|
/* G_NORETURN */
|
||||||
|
#pragma warning(error:4646) /* function declared with __declspec(noreturn) has non-void return type */
|
||||||
|
#pragma warning(error:4715) /* 'function': not all control paths return a value */
|
||||||
|
#pragma warning(error:4098) /* 'void' function returning a value */
|
||||||
|
|
||||||
#pragma warning(disable:4244) /* No possible loss of data warnings */
|
#pragma warning(disable:4244) /* No possible loss of data warnings */
|
||||||
#pragma warning(disable:4305) /* No truncation from int to char warnings */
|
#pragma warning(disable:4305) /* No truncation from int to char warnings */
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user