www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9325] New: writeln of const class instance

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9325

           Summary: writeln of const class instance
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc



This program:


import std.stdio: writeln;
class Foo { int x = 5; }
void main() {
    auto f = new Foo;
    writeln(f);
}


Prints (dmd 2.062alpha):

test1.Foo



While this:


import std.stdio: writeln;
class Foo { int x = 5; }
void main() {
    const f = new Foo;
    writeln(f);
}



Gives:

...\dmd2\src\phobos\std\format.d(2435): Error: template instance
formatObject!(LockingTextWriter, const(Foo), char)
formatObject!(LockingTextWriter, const(Foo), char) does not match template
declaration formatObject(Writer, T, Char)(ref Writer w, ref T val, ref
FormatSpec!(Char) f) if (hasToString!(T, Char))
...\dmd2\src\phobos\std\format.d(2435): Error: function expected before (), not
formatObject!(LockingTextWriter, const(Foo), char) of type void
...\dmd2\src\phobos\std\format.d(2863): Error: template instance
std.format.formatValue!(LockingTextWriter, const(Foo), char) error
instantiating
...\dmd2\src\phobos\std\format.d(415):        instantiated from here:
formatGeneric!(LockingTextWriter, const(Foo), char)
...\dmd2\src\phobos\std\stdio.d(714):        instantiated from here:
formattedWrite!(LockingTextWriter, char, const(Foo))
...\dmd2\src\phobos\std\stdio.d(1620):        instantiated from here:
write!(const(Foo),char)
test2.d(5):        instantiated from here: writeln!(const(Foo))
...\dmd2\src\phobos\std\format.d(415): Error: template instance
std.format.formatGeneric!(LockingTextWriter, const(Foo), char) error
instantiating
...\dmd2\src\phobos\std\stdio.d(714):        instantiated from here:
formattedWrite!(LockingTextWriter, char, const(Foo))
...\dmd2\src\phobos\std\stdio.d(1620):        instantiated from here:
write!(const(Foo),char)
test2.d(5):        instantiated from here: writeln!(const(Foo))
...\dmd2\src\phobos\std\stdio.d(714): Error: template instance
std.format.formattedWrite!(LockingTextWriter, char, const(Foo)) error
instantiating
...\dmd2\src\phobos\std\stdio.d(1620):        instantiated from here:
write!(const(Foo),char)
test2.d(5):        instantiated from here: writeln!(const(Foo))
...\dmd2\src\phobos\std\stdio.d(1620): Error: template instance
std.stdio.File.write!(const(Foo),char) error instantiating
test2.d(5):        instantiated from here: writeln!(const(Foo))
test2.d(5): Error: template instance std.stdio.writeln!(const(Foo)) error
instantiating

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 16 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9325


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich gmail.com
           Platform|x86                         |All
         OS/Version|Windows                     |All



17:56:16 PST ---
The platform fields are not relevant unless it's a platform-specific problem.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 16 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9325




11:22:21 PST ---
It's a problem with toString being non-const in the root Object class.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 25 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9325


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |DUPLICATE



11:25:49 PST ---
Same as Issue 7879.

*** This issue has been marked as a duplicate of issue 7879 ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 25 2013