Bug 2551 – std.format on invariant values : error and segmentation fault

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Linux
Creation time
2009-01-02T13:42:00Z
Last change time
2015-06-09T01:20:50Z
Keywords
ice-on-valid-code, patch
Assigned to
bugzilla
Creator
dransic

Attachments

IDFilenameSummaryContent-TypeSize
294format.diffPatch for std.format problems.text/plain1992

Comments

Comment #0 by dransic — 2009-01-02T13:42:55Z
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 by dsimcha — 2009-03-27T11:48:07Z
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 by dsimcha — 2009-03-27T14:28:16Z
Created attachment 294 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 by clugdbug — 2009-10-19T01:19:49Z
This was fixed between 2.026 and 2.030. I believe the segfault was fixed in 2.027.