[glib: 2/3] gdatetime: Enable compile time check of g_date_time_format() format
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib: 2/3] gdatetime: Enable compile time check of g_date_time_format() format
- Date: Wed, 31 Oct 2018 22:24:09 +0000 (UTC)
commit ae02adc3c3795bb32348c07d8f48504b41e9e2c7
Author: Christian Persch <chpe src gnome org>
Date: Wed Oct 31 11:50:07 2018 +0100
gdatetime: Enable compile time check of g_date_time_format() format
By annotating it with G_GNUC_STRFTIME.
https://gitlab.gnome.org/GNOME/glib/issues/1575
glib/gdatetime.h | 2 +-
glib/tests/gdatetime.c | 8 ++++++++
tests/datetime.c | 8 ++++++++
3 files changed, 17 insertions(+), 1 deletion(-)
---
diff --git a/glib/gdatetime.h b/glib/gdatetime.h
index 65f9965ac..20167a60d 100644
--- a/glib/gdatetime.h
+++ b/glib/gdatetime.h
@@ -261,7 +261,7 @@ GDateTime * g_date_time_to_utc (GDateTi
GLIB_AVAILABLE_IN_ALL
gchar * g_date_time_format (GDateTime *datetime,
- const gchar *format)
G_GNUC_MALLOC;
+ const gchar *format)
G_GNUC_MALLOC G_GNUC_STRFTIME (2);
G_END_DECLS
diff --git a/glib/tests/gdatetime.c b/glib/tests/gdatetime.c
index a028f6d20..a434163c2 100644
--- a/glib/tests/gdatetime.c
+++ b/glib/tests/gdatetime.c
@@ -25,6 +25,14 @@
#include <glib/gstdio.h>
#include <locale.h>
+/* The tests below exercise invalid formats and y2k-unsafe formats,
+ * so we need to silence the warnings here to pass.
+ */
+#ifdef __GNUC__
+#pragma GCC diagnostic ignored "-Wformat"
+#pragma GCC diagnostic ignored "-Wformat-y2k"
+#endif
+
#define ASSERT_DATE(dt,y,m,d) G_STMT_START { \
g_assert_nonnull ((dt)); \
g_assert_cmpint ((y), ==, g_date_time_get_year ((dt))); \
diff --git a/tests/datetime.c b/tests/datetime.c
index ae46bbaea..16f4a95e2 100644
--- a/tests/datetime.c
+++ b/tests/datetime.c
@@ -18,6 +18,14 @@
#include <locale.h>
#include <glib/glib.h>
+/* The whole purpose of this test is to pass the command line argument
+ * to g_date_time_format(), so the format argument cannot be compile-
+ * time checked. Disable the inevitable compiler warning.
+ */
+#ifdef __GNUC__
+#pragma GCC diagnostic ignored "-Wformat-nonliteral"
+#endif
+
int
main (int argc, char *argv[])
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]