After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 710862 - Allow G_GNUC_PRINTF attribute to be added to methods
Allow G_GNUC_PRINTF attribute to be added to methods
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Code Generator
unspecified
Other All
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2013-10-25 09:39 UTC by Philip Withnall
Modified: 2016-11-09 20:49 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Add G_GNUC_PRINTF/SCANF attribute for Printf/ScanfFormat functions (6.27 KB, patch)
2016-11-08 17:00 UTC, Rico Tzschichholz
none Details | Review
Add G_GNUC_PRINTF/SCANF attribute for Printf/ScanfFormat functions (8.07 KB, patch)
2016-11-08 21:43 UTC, Rico Tzschichholz
committed Details | Review

Description Philip Withnall 2013-10-25 09:39:54 UTC
I can’t find a way to get Vala to add the G_GNUC_PRINTF attribute to a method such as the following:

namespace Folks.Internal {
  [PrintfFormat]
  private static void profiling_markv (string format, va_list args) {
    …
  }
}

Shouldn’t G_GNUC_PRINTF be put in the generated C code if [PrintfFormat] is used?
Comment 1 Philip Withnall 2013-10-25 09:40:15 UTC
This is with Vala 0.22.0.26-f79fe.
Comment 2 Luca Bruno 2013-10-26 09:40:38 UTC
G_GNUC_PRINTF is used to type check the format string. Vala already type checks it.
Comment 3 Maciej (Matthew) Piechotka 2013-10-26 10:52:05 UTC
(In reply to comment #2)
> G_GNUC_PRINTF is used to type check the format string. Vala already type checks
> it.

It might be useful for libraries used by C programs/libraries. In such case Vala wouldn't type check.
Comment 4 Luca Bruno 2013-10-26 10:58:41 UTC
Yes, that's ok.
Comment 5 Philip Withnall 2013-10-26 14:49:35 UTC
(In reply to comment #2)
> G_GNUC_PRINTF is used to type check the format string. Vala already type checks
> it.

And for that reason, adding it shuts up a GCC warning (-Wsuggest-attribute=format).
Comment 6 Rico Tzschichholz 2016-11-08 17:00:38 UTC
Created attachment 339337 [details] [review]
Add G_GNUC_PRINTF/SCANF attribute for Printf/ScanfFormat functions
Comment 7 Rico Tzschichholz 2016-11-08 21:43:19 UTC
Created attachment 339355 [details] [review]
Add G_GNUC_PRINTF/SCANF attribute for Printf/ScanfFormat functions
Comment 8 Philip Withnall 2016-11-09 14:36:53 UTC
This seems to do the trick for the libfolks headers and C code, thanks:

-const gchar* folks_note_field_details_get_uid (FolksNoteFieldDetails* self);
-void folks_note_field_details_set_uid (FolksNoteFieldDetails* self, const gchar* value);
+const gchar* folks_note_field_details_get_uid (FolksNoteFieldDetails* self) G_GNUC_DEPRECATED;
+void folks_note_field_details_set_uid (FolksNoteFieldDetails* self, const gchar* value) G_GNUC_DEPRECATED;

-void folks_internal_profiling_point (const gchar* format, ...);
+void folks_internal_profiling_point (const gchar* format, ...) G_GNUC_PRINTF(1,2);

-void folks_internal_profiling_markv (const gchar* format, va_list args);
-void folks_internal_profiling_point (const gchar* format, ...);
+void folks_internal_profiling_markv (const gchar* format, va_list args) G_GNUC_PRINTF(1,0);
+void folks_internal_profiling_point (const gchar* format, ...) G_GNUC_PRINTF(1,2);