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 781061 - [PrintfFormat] generates invalid C code with functions with Error
[PrintfFormat] generates invalid C code with functions with Error
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Code Generator: GError
0.36.x
Other Linux
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2017-04-08 16:50 UTC by Jiří Janoušek
Modified: 2017-08-27 08:23 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
codegen: Adjust format-index for printf/scanf-methods which throw errors (3.30 KB, patch)
2017-08-27 07:15 UTC, Rico Tzschichholz
committed Details | Review

Description Jiří Janoušek 2017-04-08 16:50:06 UTC
printf_func_with_error.vala:

-----

[PrintfFormat]
void print(bool ok, string format, ...) throws GLib.Error
{
	var text = format.vprintf(va_list());
	if (ok)
		stdout.printf("%s", text);
	else
		throw new GLib.IOError.FAILED(text);
}

void main()
{
	print(false, "Error %s", "something");
}

-----

$ valac --version
Vala 0.36.0
$ valac --pkg gio-2.0 printf_func_with_error.vala 
printf_func_with_error.vala.c:17:1: error: format string argument is not a string type
 void print (gboolean ok, const gchar* format, GError** error, ...) G_GNUC_PRINTF(3,4);
 ^~~~
error: cc exited with status 256
Compilation failed: 1 error(s), 1 warning(s)
Comment 1 Rico Tzschichholz 2017-08-27 07:15:16 UTC
Created attachment 358501 [details] [review]
codegen: Adjust format-index for printf/scanf-methods which throw errors

If there is no explicit FormatArg annotation while this method throws an
error, it is required to mark the parameter located right before ellipsis
as format-arg to account for the parameter shifting caused by the inserted
GError parameter.