GNOME Bugzilla – Bug 638308
Variadic function generates invalid C
Last modified: 2012-09-30 17:30:42 UTC
With valac 0.11.2.76-50446 (git master, of this writing), the following Vala code generates the following invalid C code: [PrintfFormat ()] public static void print_line (string format, ...) { string output = format.vprintf (va_list ()); stdout.printf ("%s%s\n", Utils.indentation_string, output); } => void folks_inspect_utils_print_line (const gchar* format, ...) { va_list _tmp0_; /* XXX: these invalid duplicate variables aren't really used and cause a * compiler error */ va_list _tmp1_; va_list _tmp2_; gchar* _tmp3_ = NULL; gchar* _tmp4_; gchar* output; g_return_if_fail (format != NULL); va_start (_tmp0_, format); _tmp1_ = _tmp0_; _tmp2_ = _tmp1_; _tmp3_ = g_strdup_vprintf (format, _tmp2_); output = (_tmp4_ = _tmp3_, va_end (_tmp2_), _tmp4_); fprintf (stdout, "%s%s\n", folks_inspect_utils_indentation_string, output); _g_free0 (output); } ==> ========================================== utils.c: In function 'folks_inspect_utils_print_line': utils.c:375: error: incompatible types when assigning to type 'va_list' from type 'struct __va_list_tag *' utils.c:376: error: incompatible types when assigning to type 'va_list' from type 'struct __va_list_tag *' ========================================== Removing _tmp1_ and _tmp2_ and replacing instances of '_tmp2_' with '_tmp0_' in the C fixes the problem.
As was pointed out on IRC,this can be worked around by storing the va_list in a temporary variable: [PrintfFormat ()] public static void print_line (string format, ...) { var valist = va_list (); string output = format.vprintf (valist); stdout.printf ("%s%s\n", Utils.indentation_string, output); }
I confirm that since valac 0.17.5, it no longer produces the error.
Thanks for taking the time to report this bug. This particular bug has already been reported into our bug tracking system, but we are happy to tell you that the problem has already been fixed. It should be solved in the next software version. You may want to check for a software upgrade. *** This bug has been marked as a duplicate of bug 654646 ***