Skip to content

Commit

Permalink
Add const attribute more strictly
Browse files Browse the repository at this point in the history
  • Loading branch information
9rnsr committed Jul 10, 2012
1 parent 6f10e60 commit d6ffbd1
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 54 deletions.
2 changes: 1 addition & 1 deletion std/array.d
Expand Up @@ -120,7 +120,7 @@ unittest
{
int x;
this(int y) { x = y; }
override string toString() { return .to!string(x); }
override string toString() const { return .to!string(x); }
}
auto c = array([new C(1), new C(2)][]);
//writeln(c);
Expand Down
4 changes: 2 additions & 2 deletions std/conv.d
Expand Up @@ -991,15 +991,15 @@ unittest

class A
{
override string toString() { return "an A"; }
override string toString() const { return "an A"; }
}
A a;
assert(to!string(a) == "null");
a = new A;
assert(to!string(a) == "an A");

// Bug 7660
class C { override string toString() { return "C"; } }
class C { override string toString() const { return "C"; } }
struct S { C c; alias c this; }
S s; s.c = new C();
assert(to!string(s) == "C");
Expand Down
2 changes: 1 addition & 1 deletion std/csv.d
Expand Up @@ -124,7 +124,7 @@ class CSVException : Exception
this.col = col;
}

override string toString() {
override string toString() const {
return "(Row: " ~ to!string(row) ~
", Col: " ~ to!string(col) ~ ") " ~ msg;
}
Expand Down
58 changes: 33 additions & 25 deletions std/format.d
Expand Up @@ -1219,14 +1219,15 @@ unittest

class C1 { bool val; alias val this; this(bool v){ val = v; } }
class C2 { bool val; alias val this; this(bool v){ val = v; }
override string toString(){ return "C"; } }
override string toString() const { return "C"; } }
formatTest( new C1(false), "false" );
formatTest( new C1(true), "true" );
formatTest( new C2(false), "C" );
formatTest( new C2(true), "C" );

struct S1 { bool val; alias val this; }
struct S2 { bool val; alias val this; string toString(){ return "S"; } }
struct S2 { bool val; alias val this;
string toString() const { return "S"; } }
formatTest( S1(false), "false" );
formatTest( S1(true), "true" );
formatTest( S2(false), "S" );
Expand Down Expand Up @@ -1417,12 +1418,13 @@ unittest

class C1 { long val; alias val this; this(long v){ val = v; } }
class C2 { long val; alias val this; this(long v){ val = v; }
override string toString(){ return "C"; } }
override string toString() const { return "C"; } }
formatTest( new C1(10), "10" );
formatTest( new C2(10), "C" );

struct S1 { long val; alias val this; }
struct S2 { long val; alias val this; string toString(){ return "S"; } }
struct S2 { long val; alias val this;
string toString() const { return "S"; } }
formatTest( S1(10), "10" );
formatTest( S2(10), "S" );
}
Expand Down Expand Up @@ -1502,12 +1504,13 @@ unittest

class C1 { double val; alias val this; this(double v){ val = v; } }
class C2 { double val; alias val this; this(double v){ val = v; }
override string toString(){ return "C"; } }
override string toString() const { return "C"; } }
formatTest( new C1(2.25), "2.25" );
formatTest( new C2(2.25), "C" );

struct S1 { double val; alias val this; }
struct S2 { double val; alias val this; string toString(){ return "S"; } }
struct S2 { double val; alias val this;
string toString() const { return "S"; } }
formatTest( S1(2.25), "2.25" );
formatTest( S2(2.25), "S" );
}
Expand Down Expand Up @@ -1542,12 +1545,13 @@ unittest

class C1 { cdouble val; alias val this; this(cdouble v){ val = v; } }
class C2 { cdouble val; alias val this; this(cdouble v){ val = v; }
override string toString(){ return "C"; } }
override string toString() const { return "C"; } }
formatTest( new C1(3+2.25i), "3+2.25i" );
formatTest( new C2(3+2.25i), "C" );

struct S1 { cdouble val; alias val this; }
struct S2 { cdouble val; alias val this; string toString(){ return "S"; } }
struct S2 { cdouble val; alias val this;
string toString() const { return "S"; } }
formatTest( S1(3+2.25i), "3+2.25i" );
formatTest( S2(3+2.25i), "S" );
}
Expand Down Expand Up @@ -1580,12 +1584,13 @@ unittest

class C1 { idouble val; alias val this; this(idouble v){ val = v; } }
class C2 { idouble val; alias val this; this(idouble v){ val = v; }
override string toString(){ return "C"; } }
override string toString() const { return "C"; } }
formatTest( new C1(2.25i), "2.25i" );
formatTest( new C2(2.25i), "C" );

struct S1 { idouble val; alias val this; }
struct S2 { idouble val; alias val this; string toString(){ return "S"; } }
struct S2 { idouble val; alias val this;
string toString() const { return "S"; } }
formatTest( S1(2.25i), "2.25i" );
formatTest( S2(2.25i), "S" );
}
Expand Down Expand Up @@ -1616,12 +1621,13 @@ unittest

class C1 { char val; alias val this; this(char v){ val = v; } }
class C2 { char val; alias val this; this(char v){ val = v; }
override string toString(){ return "C"; } }
override string toString() const { return "C"; } }
formatTest( new C1('c'), "c" );
formatTest( new C2('c'), "C" );

struct S1 { char val; alias val this; }
struct S2 { char val; alias val this; string toString(){ return "S"; } }
struct S2 { char val; alias val this;
string toString() const { return "S"; } }
formatTest( S1('c'), "c" );
formatTest( S2('c'), "S" );
}
Expand Down Expand Up @@ -1659,10 +1665,11 @@ unittest
unittest
{
class C3 { string val; alias val this; this(string s){ val = s; }
override string toString(){ return "C"; } }
override string toString() const { return "C"; } }
formatTest( new C3("c3"), "C" );

struct S3 { string val; alias val this; string toString(){ return "S"; } }
struct S3 { string val; alias val this;
string toString() const { return "S"; } }
formatTest( S3("s3"), "S" );
}

Expand Down Expand Up @@ -1731,7 +1738,7 @@ unittest
}

static if (flags & 4)
string toString(){ return "S"; }
string toString() const { return "S"; }
}
formatTest(S!0b000([0, 1, 2]), "S!(0)([0, 1, 2])");
formatTest(S!0b001([0, 1, 2]), "[0, 1, 2]"); // Test for bug 7628
Expand All @@ -1758,7 +1765,7 @@ unittest
}

static if (flags & 4)
override string toString(){ return "C"; }
override string toString() const { return "C"; }
}
formatTest(new C!0b000([0, 1, 2]), (new C!0b000([])).toString());
formatTest(new C!0b001([0, 1, 2]), "[0, 1, 2]"); // Test for bug 7628
Expand Down Expand Up @@ -2244,12 +2251,13 @@ unittest
{
class C1 { int[char] val; alias val this; this(int[char] v){ val = v; } }
class C2 { int[char] val; alias val this; this(int[char] v){ val = v; }
override string toString(){ return "C"; } }
override string toString() const { return "C"; } }
formatTest( new C1(['c':1, 'd':2]), `['c':1, 'd':2]` );
formatTest( new C2(['c':1, 'd':2]), "C" );

struct S1 { int[char] val; alias val this; }
struct S2 { int[char] val; alias val this; string toString(){ return "S"; } }
struct S2 { int[char] val; alias val this;
string toString() const { return "S"; } }
formatTest( S1(['c':1, 'd':2]), `['c':1, 'd':2]` );
formatTest( S2(['c':1, 'd':2]), "S" );
}
Expand Down Expand Up @@ -2417,7 +2425,7 @@ unittest
class C4
{
mixin(inputRangeCode);
override string toString() { return "[012]"; }
override string toString() const { return "[012]"; }
}
class C5
{
Expand Down Expand Up @@ -2467,7 +2475,7 @@ unittest
interface Whatever {}
class C : Whatever
{
override @property string toString() { return "ab"; }
override @property string toString() const { return "ab"; }
}
Whatever val = new C;
formatTest( val, "ab" );
Expand Down Expand Up @@ -2525,9 +2533,9 @@ if ((is(T == struct) || is(T == union)) && (hasToString!(T, Char) || !isBuiltinT
unittest
{
// bug 4638
struct U8 { string toString() { return "blah"; } }
struct U16 { wstring toString() { return "blah"; } }
struct U32 { dstring toString() { return "blah"; } }
struct U8 { string toString() const { return "blah"; } }
struct U16 { wstring toString() const { return "blah"; } }
struct U32 { dstring toString() const { return "blah"; } }
formatTest( U8(), "blah" );
formatTest( U16(), "blah" );
formatTest( U32(), "blah" );
Expand Down Expand Up @@ -2558,7 +2566,7 @@ unittest
{
int n;
string s;
string toString(){ return s; }
string toString() const { return s; }
}
U2 u2;
u2.s = "hello";
Expand Down Expand Up @@ -2705,7 +2713,7 @@ unittest
// Test for issue 7869
struct S
{
string toString(){ return ""; }
string toString() const { return ""; }
}
S* p = null;
formatTest( p, "null" );
Expand Down
2 changes: 1 addition & 1 deletion std/outbuffer.d
Expand Up @@ -242,7 +242,7 @@ class OutBuffer
* Convert internal buffer to array of chars.
*/

override string toString()
override string toString() const
{
//printf("OutBuffer.toString()\n");
return cast(string) data[0 .. offset].idup;
Expand Down
2 changes: 1 addition & 1 deletion std/socketstream.d
Expand Up @@ -132,7 +132,7 @@ class SocketStream: Stream
* Does not return the entire stream because that would
* require the remote connection to be closed.
*/
override string toString()
override string toString() const
{
return sock.toString();
}
Expand Down
2 changes: 1 addition & 1 deletion std/utf.d
Expand Up @@ -72,7 +72,7 @@ class UTFException : Exception
}


override string toString()
override string toString() const
{
import std.string;
if(len == 0)
Expand Down

0 comments on commit d6ffbd1

Please sign in to comment.