From ef46a70d9abd42d07cae5897259b3292a0dede17 Mon Sep 17 00:00:00 2001 From: Hackerpilot Date: Mon, 9 Nov 2015 17:35:13 -0800 Subject: [PATCH] Check for opCast being non-const --- src/analysis/objectconst.d | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/analysis/objectconst.d b/src/analysis/objectconst.d index 2ca83d7..59d6d0c 100644 --- a/src/analysis/objectconst.d +++ b/src/analysis/objectconst.d @@ -14,7 +14,7 @@ import analysis.helpers; import dsymbol.scope_ : Scope; /** - * Checks that opEquals, opCmp, toHash, and toString are either const, + * Checks that opEquals, opCmp, toHash, 'opCast', and toString are either const, * immutable, or inout. */ class ObjectConstCheck : BaseAnalyzer @@ -40,7 +40,7 @@ class ObjectConstCheck : BaseAnalyzer { addErrorMessage(d.functionDeclaration.name.line, d.functionDeclaration.name.column, "dscanner.suspicious.object_const", - "Methods 'opCmp', 'toHash', 'opEquals', and 'toString' are non-const."); + "Methods 'opCmp', 'toHash', 'opEquals', 'opCast', and/or 'toString' are non-const."); } d.accept(this); } @@ -62,7 +62,7 @@ class ObjectConstCheck : BaseAnalyzer private static bool isInteresting(string name) { return name == "opCmp" || name == "toHash" || name == "opEquals" - || name == "toString"; + || name == "toString" || name == "opCast"; } private bool looking = false; @@ -104,22 +104,22 @@ unittest // Will warn, because none are const class Dog { - bool opEquals(Object a, Object b) // [warn]: Methods 'opCmp', 'toHash', 'opEquals', and 'toString' are non-const. + bool opEquals(Object a, Object b) // [warn]: Methods 'opCmp', 'toHash', 'opEquals', 'opCast', and/or 'toString' are non-const. { return true; } - int opCmp(Object o) // [warn]: Methods 'opCmp', 'toHash', 'opEquals', and 'toString' are non-const. + int opCmp(Object o) // [warn]: Methods 'opCmp', 'toHash', 'opEquals', 'opCast', and/or 'toString' are non-const. { return 1; } - hash_t toHash() // [warn]: Methods 'opCmp', 'toHash', 'opEquals', and 'toString' are non-const. + hash_t toHash() // [warn]: Methods 'opCmp', 'toHash', 'opEquals', 'opCast', and/or 'toString' are non-const. { return 0; } - string toString() // [warn]: Methods 'opCmp', 'toHash', 'opEquals', and 'toString' are non-const. + string toString() // [warn]: Methods 'opCmp', 'toHash', 'opEquals', 'opCast', and/or 'toString' are non-const. { return "Dog"; }