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 638308 - Variadic function generates invalid C
Variadic function generates invalid C
Status: RESOLVED DUPLICATE of bug 654646
Product: vala
Classification: Core
Component: Code Generator
0.11.x
Other Linux
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
invalid-c-code
Depends on:
Blocks: 629075
 
 
Reported: 2010-12-29 22:08 UTC by Travis Reitter
Modified: 2012-09-30 17:30 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Travis Reitter 2010-12-29 22:08:50 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.
Comment 1 Travis Reitter 2010-12-30 16:03:26 UTC
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);
    }
Comment 2 A. Syukri Abdollah 2012-09-29 17:08:42 UTC
I confirm that since valac 0.17.5, it no longer produces the error.
Comment 3 Jürg Billeter 2012-09-30 17:30:42 UTC
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 ***