937 – C-style variadic functions broken

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 937 - C-style variadic functions broken
Summary: C-style variadic functions broken
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 Linux
: P2 major
Assignee: No Owner
URL:
Keywords: rejects-valid
Depends on:
Blocks:
Reported: 2007年02月07日 10:15 UTC by Tomas Lindquist Olsen
Modified: 2014年02月16日 15:24 UTC (History)
2 users (show)

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description Tomas Lindquist Olsen 2007年02月07日 10:15:29 UTC
The code below should explain the problem sufficiently:
-------------------------------------------------------
module vararg;
// Works
void a(...)
{
 void* v = _argptr;
}
// Works
void b(char* fmt, ...)
{
 void* v = _argptr;
}
// Error: variadic functions with non-D linkage must have at least one parameter
// which is correct
extern(C)
void c(...)
{
 void* v = _argptr;
}
// Error: undefined identifier _argptr
// vararg.d(22): Error: cannot implicitly convert expression (_argptr) of type int to void*
// this is contrary to spec!
extern(C)
void d(char* fmt, ...)
{
 void* v = _argptr;
}
void main()
{
 a("a", 2, 3.0);
 b("b", 2, 3.0);
 c("c", 3, 3.0);
 d("c", 3, 3.0);
}
Comment 1 Lionello Lunesu 2007年02月09日 02:01:25 UTC
I don't think this is a bug. For extern(C) you need std.c.stdarg, va_start..va_end..
Comment 2 Tomas Lindquist Olsen 2007年02月09日 11:31:20 UTC
According to the spec the _argptr variable should be available...
So it most definitely is!
Comment 3 Daniel Green 2010年08月26日 17:26:47 UTC
While working on GDC, it was found this bug still exists in 1.063.
The problem appears to be an if statement in func.c around line 811.
"parameters" is not initialized until further down in the function. By substituting "f->parameters" the problem is resolved.
-----------------------------------------------------------
// Original if statement
if (f->linkage == LINKd || (parameters && parameters->dim))
// Modified if statement
if (f->linkage == LINKd || (f->parameters && Parameter::dim(f->parameters)))
GDC ticket.
http://bitbucket.org/goshawk/gdc/issue/57/c-style-variadic-functions-broken 


AltStyle によって変換されたページ (->オリジナル) /