D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 2551 - std.format on invariant values : error and segmentation fault
Summary: std.format on invariant values : error and segmentation fault
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: x86 Linux
: P2 normal
Assignee: Walter Bright
URL:
Keywords: ice-on-valid-code, patch
Depends on:
Blocks:
 
Reported: 2009-01-02 13:42 UTC by dransic
Modified: 2015-06-09 01:20 UTC (History)
1 user (show)

See Also:


Attachments
Patch for std.format problems. (1.95 KB, patch)
2009-03-27 14:28 UTC, David Simcha
Details | Diff

Note You need to log in before you can comment on or make changes to this issue.
Description dransic 2009-01-02 13:42:55 UTC
import std.stdio;

class Foo {
    double x;
    this(double x) { this.x = x; }
}

void main() {
    auto ifoo = new invariant(Foo)(0.);
    auto foo = new Foo(0.);
    writeln(foo.x);
    writeln(ifoo.x); // <- Error
}

causes this compiler output :

/usr/local/bin/../src/phobos/std/format.d(2048): Error: no property 'toString' for type 'invariant(double)'
/usr/local/bin/../src/phobos/std/format.d(2049): template std.stdio.PrivateFileWriter!(char).PrivateFileWriter.write(C) does not match any function template declaration
/usr/local/bin/../src/phobos/std/format.d(2049): template std.stdio.PrivateFileWriter!(char).PrivateFileWriter.write(C) cannot deduce template function from argument types !()(int)
Segmentation fault
Comment 1 David Simcha 2009-03-27 11:48:07 UTC
The problem is the following code:

    } else static if (is(const D == const(float))
                      || is(const(D) == const(double))
                      || is(const(D) == const(real))) { 
      // Do stuff.
    } else // Similar stuff for more types.

The problem is that const(immutable(T)) seems to evaluate to immutable(T), not const(T), as the following program demonstrates:

import std.stdio;

void main() {
    immutable real foo = 1.0L;
    alias const(typeof(foo)) T;
    writeln(T.stringof);  // Prints immutable(real).
}

This can probably be fixed by changing is(const(T) == const someType) tests to
is(immutable(T) == immutable someType).
Comment 2 David Simcha 2009-03-27 14:28:16 UTC
Created attachment 294 [details]
Patch for std.format problems.

Here's a patch that does what I suggested previously.  It seems to solve the problem, and all of the std.format unittests still pass, except for the ones on lines 2462 and 2464, which don't pass even without the patch.
Comment 3 Don 2009-10-19 01:19:49 UTC
This was fixed between 2.026 and 2.030. I believe the segfault was fixed in 2.027.