From a118f82ca76ce37cd3f92d031df0ce0d083d2467 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 18 Feb 2012 15:05:29 +0100 Subject: [PATCH] Tokenizer::simplifyVarDecl: Don't simplify inside parenhteses --- lib/tokenize.cpp | 2 ++ test/testtokenize.cpp | 11 +++++++++++ test/testuninitvar.cpp | 1 - 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 0a67b73b3..4d1f87560 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -5101,6 +5101,8 @@ void Tokenizer::simplifyVarDecl(bool only_k_r_fpar) continue; } else continue; + } else if (tok->str() == "(") { + tok = tok->link(); } if (tok->previous() && !Token::Match(tok->previous(), "{|}|;|)|public:|protected:|private:")) diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index b082905b3..96016a433 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -287,6 +287,7 @@ private: TEST_CASE(vardecl15); TEST_CASE(vardecl16); TEST_CASE(vardecl17); + TEST_CASE(vardecl18); TEST_CASE(vardecl_stl_1); TEST_CASE(vardecl_stl_2); TEST_CASE(vardecl_template); @@ -4636,6 +4637,16 @@ private: "a < b > :: c :: d :: e < f > y ; y = bar ( ) ;", tokenizeAndStringify(code)); } + void vardecl18() { + const char code[] = "void f() {\n" + " g((double)v1*v2, v3, v4);\n" + "}\n"; + + ASSERT_EQUALS("void f ( ) {\n" + "g ( ( double ) v1 * v2 , v3 , v4 ) ;\n" + "}", tokenizeAndStringify(code)); + } + void volatile_variables() { const char code[] = "volatile int a=0;\n" "volatile int b=0;\n" diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index a6f318c21..b6fb246d5 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -2056,7 +2056,6 @@ private: " int a, a2, a2*x; if () ;\n" " )\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: a2\n", errout.str()); } };