Bug 5461 – Invalid declaration for auto functions in .di files generated by DMD -H

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-01-19T12:00:00Z
Last change time
2013-01-16T14:59:22Z
Assigned to
nobody
Creator
dransic

Attachments

IDFilenameSummaryContent-TypeSize
872patch.txtpatch of func.c in DMD 2.051text/plain400

Comments

Comment #0 by dransic — 2011-01-19T12:00:51Z
When compiling "complex" non-templated auto functions, e.g.: auto foo() { struct Bar { int a; } auto bar = Bar(42); return bar; } with -H option, the generated .di file contains: auto foo(); which is a (rightly) invalid declaration statement. I think that either foo's body should be included in the .di file or that a warning/error should be thrown on compilation of such a function with the -H switch.
Comment #1 by dransic — 2011-01-20T08:25:32Z
Created attachment 872 patch of func.c in DMD 2.051
Comment #2 by lovelydear — 2012-04-22T15:17:53Z
With 2.059 dmd -H now produces: // D import file generated from 'bug.d' import std.stdio; struct Foo { int x; } void main();
Comment #3 by hoganmeier — 2012-05-09T09:33:11Z
? git dmd still produces 'auto foo();' for me. I think the patch could be more complex though. If it's a Voldemort type the whole body needs to be included. But what if it's a "simple" type? Then you could just print out the inferred type.
Comment #4 by adamw — 2012-05-09T09:57:54Z
(In reply to comment #3) > ? > git dmd still produces 'auto foo();' for me. > > I think the patch could be more complex though. > If it's a Voldemort type the whole body needs to be included. > But what if it's a "simple" type? Then you could just print out the inferred > type. This pull fixes this problem and a bunch of others: https://github.com/D-Programming-Language/dmd/pull/928. However, it currently fails to build on Linux and fails the unittests on Windows thanks to a problem with the dur template function in std.datetime. The solution used by this pull is to include the function body of the auto-function as that was needed to allow Phobos to build correctly using the DRT DI files.
Comment #5 by adamw — 2012-05-09T10:04:56Z
(In reply to comment #4) > (In reply to comment #3) > > ? > > git dmd still produces 'auto foo();' for me. > > > > I think the patch could be more complex though. > > If it's a Voldemort type the whole body needs to be included. > > But what if it's a "simple" type? Then you could just print out the inferred > > type. > > This pull fixes this problem and a bunch of others: > https://github.com/D-Programming-Language/dmd/pull/928. However, it currently > fails to build on Linux and fails the unittests on Windows thanks to a problem > with the dur template function in std.datetime. The solution used by this pull > is to include the function body of the auto-function as that was needed to > allow Phobos to build correctly using the DRT DI files. I forgot to mention that DMD does not know the type of an auto-function when DI files are generated. No semantic analysis has been performed and since semantic analysis could change the layout of a module you wouldn't want it to be performed.
Comment #6 by bugzilla — 2013-01-16T14:59:22Z