From 00f952f8e85527988a6171a7d9617af14c0ff5a2 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 4 Dec 2005 06:41:58 +0000 Subject: [PATCH] Add a macro to make gcc warn if a function result is ignored. (#145466, 2005-12-04 Matthias Clasen * glib/gmacros.h (G_GNUC_WARN_UNUSED_RESULT): Add a macro to make gcc warn if a function result is ignored. (#145466, Arjan van de Ven, Alex Larsson) * glib/gmem.h: Add the new attribute to g_realloc and g_try_realloc. --- ChangeLog | 9 +++++++++ ChangeLog.pre-2-10 | 9 +++++++++ ChangeLog.pre-2-12 | 9 +++++++++ docs/reference/ChangeLog | 4 ++++ docs/reference/glib/glib-sections.txt | 1 + docs/reference/glib/tmpl/macros_misc.sgml | 10 ++++++++++ glib/gmacros.h | 7 +++++++ glib/gmem.h | 4 ++-- 8 files changed, 51 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index ca48481..62683bc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2005-12-04 Matthias Clasen + + * glib/gmacros.h (G_GNUC_WARN_UNUSED_RESULT): Add a macro + to make gcc warn if a function result is ignored. (#145466, + Arjan van de Ven, Alex Larsson) + + * glib/gmem.h: Add the new attribute to g_realloc and + g_try_realloc. + 2005-12-03 Matthias Clasen * glib/glib.symbols: diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index ca48481..62683bc 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,12 @@ +2005-12-04 Matthias Clasen + + * glib/gmacros.h (G_GNUC_WARN_UNUSED_RESULT): Add a macro + to make gcc warn if a function result is ignored. (#145466, + Arjan van de Ven, Alex Larsson) + + * glib/gmem.h: Add the new attribute to g_realloc and + g_try_realloc. + 2005-12-03 Matthias Clasen * glib/glib.symbols: diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index ca48481..62683bc 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,12 @@ +2005-12-04 Matthias Clasen + + * glib/gmacros.h (G_GNUC_WARN_UNUSED_RESULT): Add a macro + to make gcc warn if a function result is ignored. (#145466, + Arjan van de Ven, Alex Larsson) + + * glib/gmem.h: Add the new attribute to g_realloc and + g_try_realloc. + 2005-12-03 Matthias Clasen * glib/glib.symbols: diff --git a/docs/reference/ChangeLog b/docs/reference/ChangeLog index a25b5ee..802baae 100644 --- a/docs/reference/ChangeLog +++ b/docs/reference/ChangeLog @@ -1,3 +1,7 @@ +2005-12-04 Matthias Clasen + + * glib/tmpl/macros_misc.sgml: Document G_GNUC_WARN_UNUSED_RESULT. + 2005-12-03 Matthias Clasen * glib/tmpl/caches.sgml: Document g_cache_value_foreach diff --git a/docs/reference/glib/glib-sections.txt b/docs/reference/glib/glib-sections.txt index e48d56f..0574188 100644 --- a/docs/reference/glib/glib-sections.txt +++ b/docs/reference/glib/glib-sections.txt @@ -323,6 +323,7 @@ G_GNUC_PRINTF G_GNUC_SCANF G_GNUC_FORMAT G_GNUC_NULL_TERMINATED +G_GNUC_WARN_UNUSED_RESULT G_GNUC_FUNCTION G_GNUC_PRETTY_FUNCTION G_GNUC_NO_INSTRUMENT diff --git a/docs/reference/glib/tmpl/macros_misc.sgml b/docs/reference/glib/tmpl/macros_misc.sgml index 82d3914..38e97c2 100644 --- a/docs/reference/glib/tmpl/macros_misc.sgml +++ b/docs/reference/glib/tmpl/macros_misc.sgml @@ -250,6 +250,16 @@ See the GNU C documentation for details. Since: 2.8 + + +Expands to the GNU C warn_unused_ersult function attribute +if the compiler is gcc, or "" if it isn't. This function +attribute makes the compiler emit a warning if the result of a function call +is ignored. See the GNU C documentation for details. + + +Since: 2.10 + diff --git a/glib/gmacros.h b/glib/gmacros.h index 21aa46d..7aba638 100644 --- a/glib/gmacros.h +++ b/glib/gmacros.h @@ -95,6 +95,13 @@ #define G_GNUC_DEPRECATED #endif /* __GNUC__ */ +#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) +#define G_GNUC_WARN_UNUSED_RESULT \ + __attribute__((warn_unused_result)) +#else +#define G_GNUC_WARN_UNUSED_RESULT +#endif /* __GNUC__ */ + /* Wrap the gcc __PRETTY_FUNCTION__ and __FUNCTION__ variables with * macros, so we can refer to them as strings unconditionally. * usage not-recommended since gcc-3.0 diff --git a/glib/gmem.h b/glib/gmem.h index ae8756e..3187aaa 100644 --- a/glib/gmem.h +++ b/glib/gmem.h @@ -47,12 +47,12 @@ typedef struct _GMemVTable GMemVTable; gpointer g_malloc (gulong n_bytes) G_GNUC_MALLOC; gpointer g_malloc0 (gulong n_bytes) G_GNUC_MALLOC; gpointer g_realloc (gpointer mem, - gulong n_bytes); + gulong n_bytes) G_GNUC_WARN_UNUSED_RESULT; void g_free (gpointer mem); gpointer g_try_malloc (gulong n_bytes) G_GNUC_MALLOC; gpointer g_try_malloc0 (gulong n_bytes) G_GNUC_MALLOC; gpointer g_try_realloc (gpointer mem, - gulong n_bytes); + gulong n_bytes) G_GNUC_WARN_UNUSED_RESULT; /* Convenience memory allocators -- 2.7.4