From f705cdce72b2c8074cae58449f987e1dba97ab85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 6 Mar 2015 17:30:20 +0100 Subject: [PATCH] Fixed #6556 (Tokenizer::simplifyVarDecl: doesn't simplify template variables properly) --- lib/tokenize.cpp | 11 ++++++++++- test/testtokenize.cpp | 9 ++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 9d7c2b8e2..b8db9a8b1 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -5637,7 +5637,16 @@ void Tokenizer::simplifyVarDecl(Token * tokBegin, Token * tokEnd, bool only_k_r_ tok2 = tok2->next(); if (tok2 && tok2->str() != ",") tok2 = nullptr; - } else + } + + // parenthesis, functions can't be declared like: + // int f1(a,b), f2(c,d); + // so if there is a comma assume this is a variable declaration + else if (Token::Match(varName, "%name% (") && Token::simpleMatch(varName->linkAt(1), ") ,")) { + tok2 = varName->linkAt(1)->next(); + } + + else tok2 = nullptr; } else { tok2 = nullptr; diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 81a1bd8ba..ffb9bd10a 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -294,7 +294,8 @@ private: TEST_CASE(vardecl_template_2); TEST_CASE(vardecl_union); TEST_CASE(vardecl_par); // #2743 - set links if variable type contains parentheses - TEST_CASE(vardecl_par2) // #3912 - set correct links + TEST_CASE(vardecl_par2); // #3912 - set correct links + TEST_CASE(vardecl_par3); // #6556 - Fred x1(a), x2(b); TEST_CASE(volatile_variables); TEST_CASE(syntax_error); TEST_CASE(syntax_error_templates_1); @@ -3816,6 +3817,12 @@ private: tokenizer.validate(); } + void vardecl_par3() { + // ticket #6556- Fred x1(a), x2(b); + const char code[] = "Fred x1(a), x2(b);"; + ASSERT_EQUALS("Fred x1 ( a ) ; Fred x2 ( b ) ;", tokenizeAndStringify(code)); + } + void vardec_static() { { // don't simplify declarations of static variables