Bug 270 – Compiler allows and crashes on typedefs of "immediate"-function types

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2006-07-29T12:31:00Z
Last change time
2014-02-15T13:21:27Z
Keywords
accepts-invalid, ice-on-invalid-code, spec
Assigned to
bugzilla
Creator
bruno.do.medeiros+deebugz
Blocks
289

Comments

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 #2 by bugzilla — 2006-08-11T19:16:39Z
Fixed DMD 0.164
Comment #3 by thomas-dloop — 2006-08-15T07:25:23Z
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 [email protected] schrieb am 2006-07-29: > http://d.puremagic.com/issues/show_bug.cgi?id=270 > 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. Added to DStress as http://dstress.kuehne.cn/nocompile/a/alias_37_A.d http://dstress.kuehne.cn/nocompile/a/alias_37_B.d http://dstress.kuehne.cn/nocompile/a/alias_37_C.d http://dstress.kuehne.cn/nocompile/a/alias_37_D.d http://dstress.kuehne.cn/nocompile/t/typedef_17_A.d http://dstress.kuehne.cn/nocompile/t/typedef_17_B.d http://dstress.kuehne.cn/nocompile/t/typedef_17_C.d http://dstress.kuehne.cn/nocompile/t/typedef_17_D.d Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFE4bgSLK5blCcjpWoRAp3+AJsFKx96ZcXQhdRZ63edKQwKRUnE6QCfby6k mowRlio1tzWR9pZl65Gp+FA= =G6XF -----END PGP SIGNATURE-----
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