From 494dd2ba3a8145bd060b49e094cb59857ee70302 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 28 Feb 2019 15:56:25 +0100 Subject: [PATCH] Revert "Improved isVariableChangedByFunctionCall, better logic when parameter might be passed by reference" This reverts commit 14a0031e884c765e8ef5705e5330dfc26f985e11. --- lib/astutils.cpp | 10 ++-------- test/testastutils.cpp | 2 +- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index d7f712156..8c5c43823 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -811,8 +811,6 @@ bool isVariableChangedByFunctionCall(const Token *tok, const Settings *settings, if (!tok) return false; - const Token * const tok1 = tok; - // address of variable const bool addressOf = tok->astParent() && tok->astParent()->isUnaryOp("&"); @@ -846,13 +844,10 @@ bool isVariableChangedByFunctionCall(const Token *tok, const Settings *settings, tok = tok->link(); else if (Token::Match(tok->previous(), "%name% (")) break; - else if (Token::simpleMatch(tok->previous(), "> (") && tok->previous()->link()) - break; tok = tok->previous(); } if (!tok || tok->str() != "(") return false; - const bool possiblyPassedByReference = (tok->next() == tok1 || Token::simpleMatch(tok->previous(), ", %name% [,)]")); tok = tok->previous(); if (tok && tok->link() && tok->str() == ">") tok = tok->link()->previous(); @@ -884,13 +879,12 @@ bool isVariableChangedByFunctionCall(const Token *tok, const Settings *settings, // => it is assumed that parameter is an in parameter (TODO: this is a bad heuristic) if (!addressOf && settings && settings->library.isnullargbad(tok, 1+argnr)) return false; - // possible pass-by-reference => inconclusive - if (possiblyPassedByReference) { + // addressOf => inconclusive + if (!addressOf) { if (inconclusive != nullptr) *inconclusive = true; return false; } - // Safe guess: Assume that parameter is changed by function call return true; } diff --git a/test/testastutils.cpp b/test/testastutils.cpp index a66e43fe3..c5cf38415 100644 --- a/test/testastutils.cpp +++ b/test/testastutils.cpp @@ -135,7 +135,7 @@ private: "}"; inconclusive = false; ASSERT_EQUALS(false, isVariableChangedByFunctionCall(code, "x ) ;", &inconclusive)); - ASSERT_EQUALS(true, inconclusive); + // FIXME : ASSERT_EQUALS(true, inconclusive); } bool nextAfterAstRightmostLeaf(const char code[], const char parentPattern[], const char rightPattern[]) {