[glib: 1/3] gmacros: Add G_GNUC_STRFTIME macro



commit d62a07831c1fc047b3eebd508cfa47212e2cbe80
Author: Christian Persch <chpe src gnome org>
Date:   Wed Oct 31 11:50:07 2018 +0100

    gmacros: Add G_GNUC_STRFTIME macro
    
    Analogous to G_GNUC_PRINTF and G_GNUC_SCANF, to annotate
    functions similar to strftime.
    
    https://gitlab.gnome.org/GNOME/glib/issues/1575

 docs/reference/glib/glib-sections.txt |  1 +
 glib/docs.c                           | 17 +++++++++++++++++
 glib/gmacros.h                        |  5 +++++
 3 files changed, 23 insertions(+)
---
diff --git a/docs/reference/glib/glib-sections.txt b/docs/reference/glib/glib-sections.txt
index d875f9a3a..e59a1c1e4 100644
--- a/docs/reference/glib/glib-sections.txt
+++ b/docs/reference/glib/glib-sections.txt
@@ -442,6 +442,7 @@ G_GNUC_FALLTHROUGH
 G_GNUC_UNUSED
 G_GNUC_PRINTF
 G_GNUC_SCANF
+G_GNUC_STRFTIME
 G_GNUC_FORMAT
 G_GNUC_NULL_TERMINATED
 G_GNUC_WARN_UNUSED_RESULT
diff --git a/glib/docs.c b/glib/docs.c
index 5212bb582..562fef0aa 100644
--- a/glib/docs.c
+++ b/glib/docs.c
@@ -2359,6 +2359,23 @@
  * for details.
  */
 
+/**
+ * G_GNUC_STRFTIME:
+ * @format_idx: the index of the argument corresponding to
+ *     the format string (the arguments are numbered from 1)
+ *
+ * Expands to the GNU C strftime format function attribute if the compiler
+ * is gcc. This is used for declaring functions which take a format argument
+ * which is passed to strftime() or an API implementing its formats. It allows
+ * the compiler check the format passed to the function.
+ *
+ * See the
+ * [GNU C 
documentation](https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-Wformat-3288)
+ * for details.
+ *
+ * Since: 2.60
+ */
+
 /**
  * G_GNUC_FORMAT:
  * @arg_idx: the index of the argument
diff --git a/glib/gmacros.h b/glib/gmacros.h
index 0432d9cad..5212d2fe8 100644
--- a/glib/gmacros.h
+++ b/glib/gmacros.h
@@ -165,11 +165,15 @@
   __attribute__((__format__ (gnu_printf, format_idx, arg_idx)))
 #define G_GNUC_SCANF( format_idx, arg_idx )     \
   __attribute__((__format__ (gnu_scanf, format_idx, arg_idx)))
+#define G_GNUC_STRFTIME( format_idx )    \
+  __attribute__((__format__ (gnu_strftime, format_idx, 0)))
 #else
 #define G_GNUC_PRINTF( format_idx, arg_idx )    \
   __attribute__((__format__ (__printf__, format_idx, arg_idx)))
 #define G_GNUC_SCANF( format_idx, arg_idx )     \
   __attribute__((__format__ (__scanf__, format_idx, arg_idx)))
+#define G_GNUC_STRFTIME( format_idx )    \
+  __attribute__((__format__ (__strftime__, format_idx, 0)))
 #endif
 #define G_GNUC_FORMAT( arg_idx )                \
   __attribute__((__format_arg__ (arg_idx)))
@@ -184,6 +188,7 @@
 #else   /* !__GNUC__ */
 #define G_GNUC_PRINTF( format_idx, arg_idx )
 #define G_GNUC_SCANF( format_idx, arg_idx )
+#define G_GNUC_STRFTIME( format_idx )
 #define G_GNUC_FORMAT( arg_idx )
 #define G_GNUC_NORETURN
 #define G_GNUC_CONST


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]