From 7021cb2c6b068cdc02de0271cf7d57f18363895a Mon Sep 17 00:00:00 2001 From: Frank Zingsheim Date: Sun, 2 Aug 2015 09:11:51 +0200 Subject: [PATCH] Fixed #6284 (Token::Match called with varid 0. Constants) --- lib/tokenize.cpp | 6 +++++- test/testtokenize.cpp | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 40fdfbfc7..31fd5601e 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2803,7 +2803,11 @@ void Tokenizer::setVarId() if (rhs) continue; - if (tok3->isLiteral() || (tok3->isName() && (variableId.find(tok3->str()) != variableId.end())) || tok3->isOp() || notstart.find(tok3->str()) != notstart.end()) { + if (tok3->isLiteral() || + (tok3->isName() && (variableId.find(tok3->str()) != variableId.end())) || + tok3->isOp() || + tok3->str() == "(" || + notstart.find(tok3->str()) != notstart.end()) { decl = true; break; } diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 33bc03a88..a64158731 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -5425,6 +5425,40 @@ private: ASSERT_EQUALS("return doSomething ( X ) , 0 ;", tokenizeAndStringify(code, false)); ASSERT_EQUALS("", errout.str()); } + + { + const char code[] = "const int x(1);" + "const int y(2);" + "const int z((x+1)*y);" + "f(z);"; + ASSERT_EQUALS("f ( 4 ) ;", tokenizeAndStringify(code, true)); + ASSERT_EQUALS("", errout.str()); + } + + { + const char code[] = "const int x(1);" + "const int y(2);" + "const int z((x+1)*y);" + "f(&z);"; + ASSERT_EQUALS("const int z ( 4 ) ; f ( & z ) ;", tokenizeAndStringify(code, true)); + ASSERT_EQUALS("", errout.str()); + } + + { + const char code[] = "const bool x(true);" + "const bool y(!x);" + "f(y);"; + ASSERT_EQUALS("f ( false ) ;", tokenizeAndStringify(code, true)); + ASSERT_EQUALS("", errout.str()); + } + + { + const char code[] = "const bool x(true);" + "const bool y(!x);" + "f(&y);"; + ASSERT_EQUALS("const bool y ( false ) ; f ( & y ) ;", tokenizeAndStringify(code, true)); + ASSERT_EQUALS("", errout.str()); + } } void simplifyInitVar2() {