digitalmars.D.bugs - [Issue 1814] New: DMD/GDC does not prevent typedef violations
- d-bugmail puremagic.com (26/26) Feb 03 2008 http://d.puremagic.com/issues/show_bug.cgi?id=1814
- d-bugmail puremagic.com (7/21) Feb 03 2008 http://d.puremagic.com/issues/show_bug.cgi?id=1814
- d-bugmail puremagic.com (18/18) Mar 04 2008 http://d.puremagic.com/issues/show_bug.cgi?id=1814
http://d.puremagic.com/issues/show_bug.cgi?id=1814 Summary: DMD/GDC does not prevent typedef violations Product: D Version: unspecified Platform: All OS/Version: All Status: NEW Keywords: accepts-invalid Severity: major Priority: P2 Component: DMD AssignedTo: bugzilla digitalmars.com ReportedBy: default_357-line yahoo.de The spec says the following about typedefs: "A typedef or enum can be implicitly converted to its base type, but going the other way requires an explicit conversion." Why, then, does the following work (on the most recent DMD and GDC)? import std.stdio; typedef int Foo; void test(Foo foo) { } void main() { test(3); /*ILLEGAL!*/ Foo f = cast(Foo) 2; writefln(f+3); /*ALSO ILLEGAL*/ } This basically makes typedef no better than alias. Looking forward to a fix, --downs --
Feb 03 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1814The spec says the following about typedefs: "A typedef or enum can be implicitly converted to its base type, but going the other way requires an explicit conversion." Why, then, does the following work (on the most recent DMD and GDC)? import std.stdio; typedef int Foo; void test(Foo foo) { } void main() { test(3); /*ILLEGAL!*/ Foo f = cast(Foo) 2; writefln(f+3); /*ALSO ILLEGAL*/ }Ignore the second one, please, I understand what happens. The first one is still wrong, though.--downs--downs :) --
Feb 03 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1814 bugzilla digitalmars.com changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |INVALID It turns out that disallowing: typedef int Foo; Foo f; f = 3; is very onerous. It will require inserting casts everywhere a literal is used. So implicitly converting an integer literal to a typedef is allowed. What is not allowed is: int i = 3; f = i; I'll update the documentation to clarify this. --
Mar 04 2008