From ce1aa1e01136277776f6786f9318e7deb58577e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 14 Mar 2014 20:08:34 +0100 Subject: [PATCH] Library: I had misunderstood const/pure a little so I corrected cfg and code --- cfg/std.cfg | 2 +- lib/checkother.cpp | 14 +++++++------- lib/library.cpp | 5 +++-- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/cfg/std.cfg b/cfg/std.cfg index 2c3e03066..cdf4c98e2 100644 --- a/cfg/std.cfg +++ b/cfg/std.cfg @@ -43,7 +43,7 @@ false false false - false + false false false false 0- diff --git a/lib/checkother.cpp b/lib/checkother.cpp index b3e1ec00b..aedf2e33c 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1370,9 +1370,9 @@ void CheckOther::checkIncorrectLogicOperator() if (!MathLib::isInt(value2) && !MathLib::isFloat(value2)) continue; - if (isSameExpression(comp1, comp2, _settings->library.functionconst)) + if (isSameExpression(comp1, comp2, _settings->library.functionpure)) continue; // same expressions => only report that there are same expressions - if (!isSameExpression(expr1, expr2, _settings->library.functionconst)) + if (!isSameExpression(expr1, expr2, _settings->library.functionpure)) continue; const bool isfloat = astIsFloat(expr1) || MathLib::isFloat(value1) || astIsFloat(expr2) || MathLib::isFloat(value2); @@ -2873,18 +2873,18 @@ void CheckOther::checkDuplicateExpression() if (tok->isOp() && tok->astOperand1() && !Token::Match(tok, "+|-|*|/|%|=|<<|>>")) { if (Token::Match(tok, "==|!=|-") && astIsFloat(tok->astOperand1())) continue; - if (isSameExpression(tok->astOperand1(), tok->astOperand2(), _settings->library.functionconst)) + if (isSameExpression(tok->astOperand1(), tok->astOperand2(), _settings->library.functionpure)) duplicateExpressionError(tok, tok, tok->str()); - else if (tok->astOperand2() && tok->str() == tok->astOperand1()->str() && isSameExpression(tok->astOperand2(), tok->astOperand1()->astOperand2(), _settings->library.functionconst)) + else if (tok->astOperand2() && tok->str() == tok->astOperand1()->str() && isSameExpression(tok->astOperand2(), tok->astOperand1()->astOperand2(), _settings->library.functionpure)) duplicateExpressionError(tok->astOperand2(), tok->astOperand2(), tok->str()); else if (tok->astOperand2()) { const Token *ast1 = tok->astOperand1(); while (ast1 && tok->str() == ast1->str()) { - if (isSameExpression(ast1->astOperand1(), tok->astOperand2(), _settings->library.functionconst)) + if (isSameExpression(ast1->astOperand1(), tok->astOperand2(), _settings->library.functionpure)) duplicateExpressionError(ast1->astOperand1(), tok->astOperand2(), tok->str()); - else if (isSameExpression(ast1->astOperand2(), tok->astOperand2(), _settings->library.functionconst)) + else if (isSameExpression(ast1->astOperand2(), tok->astOperand2(), _settings->library.functionpure)) duplicateExpressionError(ast1->astOperand2(), tok->astOperand2(), tok->str()); - if (!isConstExpression(ast1->astOperand2(), _settings->library.functionconst)) + if (!isConstExpression(ast1->astOperand2(), _settings->library.functionpure)) break; ast1 = ast1->astOperand1(); } diff --git a/lib/library.cpp b/lib/library.cpp index 74c92126b..b57613d64 100644 --- a/lib/library.cpp +++ b/lib/library.cpp @@ -136,9 +136,10 @@ bool Library::load(const tinyxml2::XMLDocument &doc) _noreturn[name] = (strcmp(functionnode->GetText(), "true") == 0); else if (strcmp(functionnode->Name(), "pure") == 0) functionpure.insert(name); - else if (strcmp(functionnode->Name(), "const") == 0) + else if (strcmp(functionnode->Name(), "const") == 0) { functionconst.insert(name); - else if (strcmp(functionnode->Name(),"leak-ignore")==0) + functionpure.insert(name); // a constant function is pure + } else if (strcmp(functionnode->Name(),"leak-ignore")==0) leakignore.insert(name); else if (strcmp(functionnode->Name(), "arg") == 0 && functionnode->Attribute("nr") != nullptr) { const bool bAnyArg = strcmp(functionnode->Attribute("nr"),"any")==0;