diff --git a/std/array.d b/std/array.d index 577b04f2f6f..410c5f6b435 100644 --- a/std/array.d +++ b/std/array.d @@ -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); diff --git a/std/conv.d b/std/conv.d index 1becb418950..7306ff0b9e0 100644 --- a/std/conv.d +++ b/std/conv.d @@ -991,7 +991,7 @@ unittest class A { - override string toString() { return "an A"; } + override string toString() const { return "an A"; } } A a; assert(to!string(a) == "null"); @@ -999,7 +999,7 @@ unittest 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"); diff --git a/std/csv.d b/std/csv.d index 9d4363ecbe6..abcd4fb10ef 100644 --- a/std/csv.d +++ b/std/csv.d @@ -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; } diff --git a/std/format.d b/std/format.d index 691cb6b1fbe..eca6b70a028 100644 --- a/std/format.d +++ b/std/format.d @@ -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" ); @@ -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" ); } @@ -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" ); } @@ -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" ); } @@ -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" ); } @@ -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" ); } @@ -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" ); } @@ -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 @@ -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 @@ -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" ); } @@ -2417,7 +2425,7 @@ unittest class C4 { mixin(inputRangeCode); - override string toString() { return "[012]"; } + override string toString() const { return "[012]"; } } class C5 { @@ -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" ); @@ -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" ); @@ -2558,7 +2566,7 @@ unittest { int n; string s; - string toString(){ return s; } + string toString() const { return s; } } U2 u2; u2.s = "hello"; @@ -2705,7 +2713,7 @@ unittest // Test for issue 7869 struct S { - string toString(){ return ""; } + string toString() const { return ""; } } S* p = null; formatTest( p, "null" ); diff --git a/std/outbuffer.d b/std/outbuffer.d index 32730b2aa3c..e2f6f6855b8 100644 --- a/std/outbuffer.d +++ b/std/outbuffer.d @@ -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; diff --git a/std/socketstream.d b/std/socketstream.d index e89358eb6a4..5ec4bfb3b5b 100644 --- a/std/socketstream.d +++ b/std/socketstream.d @@ -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(); } diff --git a/std/utf.d b/std/utf.d index 0f34e447b9f..5fd785c4e27 100644 --- a/std/utf.d +++ b/std/utf.d @@ -72,7 +72,7 @@ class UTFException : Exception } - override string toString() + override string toString() const { import std.string; if(len == 0) diff --git a/std/xml.d b/std/xml.d index d0587bcd965..135cff794ed 100644 --- a/std/xml.d +++ b/std/xml.d @@ -824,7 +824,7 @@ class Element : Item * if (e1 == e2) { } * -------------- */ - override bool opEquals(const Object o) + override const bool opEquals(const Object o) { const element = toType!(const Element)(o); auto len = items.length; @@ -848,7 +848,7 @@ class Element : Item * if (e1 < e2) { } * -------------- */ - override int opCmp(const Object o) + override const int opCmp(const Object o) { const element = toType!(const Element)(o); for (uint i=0; ; ++i) @@ -867,7 +867,7 @@ class Element : Item * You should rarely need to call this function. It exists so that Elements * can be used as associative array keys. */ - override hash_t toHash() + override const hash_t toHash() { hash_t hash = tag.toHash(); foreach(item;items) hash += item.toHash(); @@ -1233,7 +1233,7 @@ class Comment : Item * if (item1 == item2) { } * -------------- */ - override bool opEquals(const Object o) + override const bool opEquals(const Object o) { const item = toType!(const Item)(o); const t = cast(Comment)item; @@ -1252,7 +1252,7 @@ class Comment : Item * if (item1 < item2) { } * -------------- */ - override int opCmp(const Object o) + override const int opCmp(const Object o) { const item = toType!(const Item)(o); const t = cast(Comment)item; @@ -1266,7 +1266,7 @@ class Comment : Item * You should rarely need to call this function. It exists so that Comments * can be used as associative array keys. */ - override hash_t toHash() { return hash(content); } + override const hash_t toHash() { return hash(content); } /** * Returns a string representation of this comment @@ -1312,7 +1312,7 @@ class CData : Item * if (item1 == item2) { } * -------------- */ - override bool opEquals(const Object o) + override const bool opEquals(const Object o) { const item = toType!(const Item)(o); const t = cast(CData)item; @@ -1331,7 +1331,7 @@ class CData : Item * if (item1 < item2) { } * -------------- */ - override int opCmp(const Object o) + override const int opCmp(const Object o) { const item = toType!(const Item)(o); const t = cast(CData)item; @@ -1345,7 +1345,7 @@ class CData : Item * You should rarely need to call this function. It exists so that CDatas * can be used as associative array keys. */ - override hash_t toHash() { return hash(content); } + override const hash_t toHash() { return hash(content); } /** * Returns a string representation of this CData section @@ -1389,7 +1389,7 @@ class Text : Item * if (item1 == item2) { } * -------------- */ - override bool opEquals(const Object o) + override const bool opEquals(const Object o) { const item = toType!(const Item)(o); const t = cast(Text)item; @@ -1408,7 +1408,7 @@ class Text : Item * if (item1 < item2) { } * -------------- */ - override int opCmp(const Object o) + override const int opCmp(const Object o) { const item = toType!(const Item)(o); const t = cast(Text)item; @@ -1422,7 +1422,7 @@ class Text : Item * You should rarely need to call this function. It exists so that Texts * can be used as associative array keys. */ - override hash_t toHash() { return hash(content); } + override const hash_t toHash() { return hash(content); } /** * Returns a string representation of this Text section @@ -1471,7 +1471,7 @@ class XMLInstruction : Item * if (item1 == item2) { } * -------------- */ - override bool opEquals(const Object o) + override const bool opEquals(const Object o) { const item = toType!(const Item)(o); const t = cast(XMLInstruction)item; @@ -1490,7 +1490,7 @@ class XMLInstruction : Item * if (item1 < item2) { } * -------------- */ - override int opCmp(const Object o) + override const int opCmp(const Object o) { const item = toType!(const Item)(o); const t = cast(XMLInstruction)item; @@ -1504,7 +1504,7 @@ class XMLInstruction : Item * You should rarely need to call this function. It exists so that * XmlInstructions can be used as associative array keys. */ - override hash_t toHash() { return hash(content); } + override const hash_t toHash() { return hash(content); } /** * Returns a string representation of this XmlInstruction @@ -1550,7 +1550,7 @@ class ProcessingInstruction : Item * if (item1 == item2) { } * -------------- */ - override bool opEquals(const Object o) + override const bool opEquals(const Object o) { const item = toType!(const Item)(o); const t = cast(ProcessingInstruction)item; @@ -1569,7 +1569,7 @@ class ProcessingInstruction : Item * if (item1 < item2) { } * -------------- */ - override int opCmp(const Object o) + override const int opCmp(const Object o) { const item = toType!(const Item)(o); const t = cast(ProcessingInstruction)item; @@ -1583,7 +1583,7 @@ class ProcessingInstruction : Item * You should rarely need to call this function. It exists so that * ProcessingInstructions can be used as associative array keys. */ - override hash_t toHash() { return hash(content); } + override const hash_t toHash() { return hash(content); } /** * Returns a string representation of this ProcessingInstruction @@ -1599,13 +1599,13 @@ class ProcessingInstruction : Item abstract class Item { /// Compares with another Item of same type for equality - abstract override bool opEquals(const Object o); + abstract override const bool opEquals(const Object o); /// Compares with another Item of same type - abstract override int opCmp(const Object o); + abstract override const int opCmp(const Object o); /// Returns the hash of this item - abstract override hash_t toHash(); + abstract override const hash_t toHash(); /// Returns a string representation of this item abstract override const string toString(); @@ -2070,7 +2070,7 @@ class ElementParser /** * Returns that part of the element which has already been parsed */ - const override string toString() + override const string toString() { assert(elementStart.length >= s.length); return elementStart[0 .. elementStart.length - s.length];