3306 – bad function/delegate literal generated into header files

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3306 - bad function/delegate literal generated into header files
Summary: bad function/delegate literal generated into header files
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: patch, wrong-code
Depends on:
Blocks:
Reported: 2009年09月07日 23:42 UTC by Rainer Schuetze
Modified: 2015年06月09日 01:26 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 Rainer Schuetze 2009年09月07日 23:42:31 UTC
While trying to compile tango with dmd 1.046, I ran into the a problem with the di-header generated for atomic.d. A reduced version that reproduces the bug in dmd 2.032 aswell is
test.d:
int foo(int function() fn)
{
	return fn();
}
int bar(T)()
{
	return foo(function int (){ return 0; });
}
>dmd -c -H test.d
>dmd -c test.di
test.di(10): found 'function' when expecting '.' following 'int'
test.di(10): found '(' when expecting identifier following 'int.'
test.di(11): found '{' when expecting ';' following 'return statement'
test.di(14): Declaration expected, not ')'
test.di(16): unrecognized declaration
This is caused by a wrong function literal being generated into the di-file:
// D import file generated from 'test.d'
int foo(int function() fn)
{
return fn();
}
template bar(T)
{
int bar()
{
return foo(int function()
{
return 0;
}
);
}
}
Note the difference "foo(int function()..." and "foo(function int ()...".
Comment 1 Rainer Schuetze 2009年09月07日 23:46:41 UTC
Here is the patch that fixes the problem, but I have no idea why it was implemented the way it was before. There might be other places that may need the original implementation.
--- func.c	(revision 196)
+++ func.c	(working copy)
@@ -2426,15 +2426,9 @@
 
 void FuncLiteralDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
 {
- static Identifier *idfunc;
- static Identifier *iddel;
-
- if (!idfunc)
-	idfunc = new Identifier("function", 0);
- if (!iddel)
-	iddel = new Identifier("delegate", 0);
-
- type->toCBuffer(buf, ((tok == TOKdelegate) ? iddel : idfunc), hgs);
+ buf->writestring(kind());
+ buf->writeByte(' ');
+ type->toCBuffer(buf, NULL, hgs);
 bodyToCBuffer(buf, hgs);
 }
Comment 2 Walter Bright 2010年02月04日 20:34:08 UTC
Changelog 366
Comment 3 Kosmonaut 2010年02月04日 22:45:39 UTC
(In reply to comment #2)
> Changelog 366
http://www.dsource.org/projects/dmd/changeset/366 
Comment 4 Walter Bright 2010年03月08日 22:19:39 UTC
Fixed dmd 1.057 and 2.041


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