Merge pull request #672 from wilzbach/fix-671

Fix #671 - False positive in infinite range check
merged-on-behalf-of: BBasile <BBasile@users.noreply.github.com>
This commit is contained in:
The Dlang Bot 2018-06-26 09:27:43 +02:00 committed by GitHub
commit 0ec1e9557a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 3 deletions

View File

@ -62,6 +62,8 @@ final class IncorrectInfiniteRangeCheck : BaseAnalyzer
override void visit(const ReturnStatement rs)
{
if (inStruct == 0 || line == size_t.max) // not within a struct yet
return;
if (!rs.expression || rs.expression.items.length != 1)
return;
UnaryExpression unary = cast(UnaryExpression) rs.expression.items[0];
@ -82,7 +84,7 @@ private:
uint inStruct;
enum string KEY = "dscanner.suspicious.incorrect_infinite_range";
enum string MESSAGE = "Use `enum bool empty = false;` to define an infinite range.";
size_t line;
size_t line = size_t.max;
size_t column;
}
@ -123,8 +125,6 @@ class C { bool empty() { return false; } } // [warn]: %1$s
}c
.format(IncorrectInfiniteRangeCheck.MESSAGE), sac);
stderr.writeln("Unittest for IncorrectInfiniteRangeCheck passed.");
}
// test for https://github.com/dlang-community/D-Scanner/issues/656
@ -136,3 +136,23 @@ version(none) struct Foo
return;
}
}
unittest
{
import std.stdio : stderr;
import dscanner.analysis.config : StaticAnalysisConfig, Check, disabledConfig;
import std.format : format;
StaticAnalysisConfig sac = disabledConfig();
sac.incorrect_infinite_range_check = Check.enabled;
assertAnalyzerWarnings(q{
enum isAllZeroBits = ()
{
if (true)
return true;
else
return false;
}();
}, sac);
stderr.writeln("Unittest for IncorrectInfiniteRangeCheck passed.");
}