Fix false positive with non-const function calls
This commit is contained in:
parent
a880469c5a
commit
b2ea78543b
|
@ -2444,6 +2444,7 @@ namespace {
|
||||||
Expressions(const SymbolDatabase *symbolDatabase, const
|
Expressions(const SymbolDatabase *symbolDatabase, const
|
||||||
std::list<Function> &constFunctions)
|
std::list<Function> &constFunctions)
|
||||||
: _start(0),
|
: _start(0),
|
||||||
|
_lastTokens(0),
|
||||||
_symbolDatabase(symbolDatabase),
|
_symbolDatabase(symbolDatabase),
|
||||||
_constFunctions(constFunctions) { }
|
_constFunctions(constFunctions) { }
|
||||||
|
|
||||||
|
@ -2451,13 +2452,18 @@ namespace {
|
||||||
const std::string &e = _expression.str();
|
const std::string &e = _expression.str();
|
||||||
if (!e.empty()) {
|
if (!e.empty()) {
|
||||||
std::map<std::string, ExpressionTokens>::iterator it = _expressions.find(e);
|
std::map<std::string, ExpressionTokens>::iterator it = _expressions.find(e);
|
||||||
|
bool lastInconclusive = _lastTokens && _lastTokens->inconclusiveFunction;
|
||||||
if (it == _expressions.end()) {
|
if (it == _expressions.end()) {
|
||||||
ExpressionTokens exprTokens(_start, end);
|
ExpressionTokens exprTokens(_start, end);
|
||||||
exprTokens.inconclusiveFunction = inconclusiveFunctionCall(
|
exprTokens.inconclusiveFunction = lastInconclusive || inconclusiveFunctionCall(
|
||||||
_symbolDatabase, _constFunctions, exprTokens);
|
_symbolDatabase, _constFunctions, exprTokens);
|
||||||
_expressions.insert(std::make_pair(e, exprTokens));
|
_expressions.insert(std::make_pair(e, exprTokens));
|
||||||
|
_lastTokens = &_expressions.find(e)->second;
|
||||||
} else {
|
} else {
|
||||||
it->second.count += 1;
|
ExpressionTokens &expr = it->second;
|
||||||
|
expr.count += 1;
|
||||||
|
expr.inconclusiveFunction = expr.inconclusiveFunction || lastInconclusive;
|
||||||
|
_lastTokens = &expr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_expression.str("");
|
_expression.str("");
|
||||||
|
@ -2478,6 +2484,7 @@ namespace {
|
||||||
std::map<std::string, ExpressionTokens> _expressions;
|
std::map<std::string, ExpressionTokens> _expressions;
|
||||||
std::ostringstream _expression;
|
std::ostringstream _expression;
|
||||||
const Token *_start;
|
const Token *_start;
|
||||||
|
ExpressionTokens *_lastTokens;
|
||||||
const SymbolDatabase *_symbolDatabase;
|
const SymbolDatabase *_symbolDatabase;
|
||||||
const std::list<Function> &_constFunctions;
|
const std::list<Function> &_constFunctions;
|
||||||
};
|
};
|
||||||
|
|
|
@ -3762,6 +3762,11 @@ private:
|
||||||
" if (str == \"(\" || str == \"(\") {}\n"
|
" if (str == \"(\" || str == \"(\") {}\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2]: (style) Same expression on both sides of '||'.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2]: (style) Same expression on both sides of '||'.\n", errout.str());
|
||||||
|
|
||||||
|
check("void foo() {\n"
|
||||||
|
" if (bar(a) && !strcmp(a, b) && bar(a) && !strcmp(a, b)) {}\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void duplicateExpression4() {
|
void duplicateExpression4() {
|
||||||
|
|
Loading…
Reference in New Issue