Comment #0 by bruno.do.medeiros+deebugz — 2006-07-29T12:31:07Z
Compiler allows and crashes on typedefs of "immediate"-function types,
where "immediate-function" types are non-pointer function types.
Code example:
typedef int ft(int);
//typedef typeof(test) fp; // This alternative typedef also crashes
void test()
{
ft[10] a;
}
---
This raises the issue: should a typedef of an "immediate" function type even be allowed? Seems to me not, as one can't use the typedef for any declaration!
((
While we're at it, should storage attributes be allowed in a typedef? Like: "typedef static const final override auto int sometype;" ?
It also seems to me not.
))
Whichever the case (even without changes), the spec grammar should also be corrected. An example of a current doc error is:
typedef Decl
Decl:
...
BasicType Declarator FunctionBody
but the compiler does not accept typedefs with function bodies.
Comment #1 by aldacron — 2006-08-01T01:51:13Z
[email protected] wrote:
> http://d.puremagic.com/issues/show_bug.cgi?id=270
>
> Summary: Compiler allows and crashes on typedefs of "immediate"-
> function types
> Product: D
> Version: 0.163
> Platform: PC
> OS/Version: Windows
> Status: NEW
> Keywords: accepts-invalid, ice-on-invalid-code, spec
> Severity: normal
> Priority: P2
> Component: DMD
> AssignedTo: [email protected]
> ReportedBy: [email protected]
>
>
> Compiler allows and crashes on typedefs of "immediate"-function types,
> where "immediate-function" types are non-pointer function types.
> Code example:
>
> typedef int ft(int);
> //typedef typeof(test) fp; // This alternative typedef also crashes
>
> void test()
> {
> ft[10] a;
> }
>
> ---
> This raises the issue: should a typedef of an "immediate" function type even be
> allowed? Seems to me not, as one can't use the typedef for any declaration!
You can make a pointer to it.
ft * p;
But I agree that there doesn't seem to be any need for it. I find those
declarations terribly confusing. I think it's another one of the silly C
corner cases that we'd be better off without.
Also, it's worth considering entirely removing C-style function
declarations from D, now that we have the htod tool. My experience in
manually converting the Windows API headers was that there is negligible
effort involved in converting to D 'function' declarations, anyway.
Comment #4 by bruno.do.medeiros+deebugz — 2006-08-15T12:40:07Z
Static arrays (as the first example) now work correctly, but there is still the same bug with dynamic arrays. (Associative Arrays seem to work correctly.)
Example:
-----
typedef int ft(int);
ft[] x; // is allowed
void test() {
x.length = 2; // crashes DMD
}
Comment #5 by bruno.do.medeiros+deebugz — 2006-08-15T19:17:07Z
Spawned new bug and reverted this one to: Fixed DMD 0.164