From 036f3894f1f86dac1f44d66e17459c1d2fdddc3e Mon Sep 17 00:00:00 2001 From: Reijo Tomperi Date: Mon, 5 Oct 2009 14:30:05 +0300 Subject: [PATCH] Fix simplifyRedundantParanthesis() to work after '}' --- src/tokenize.cpp | 2 +- test/testsimplifytokens.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/tokenize.cpp b/src/tokenize.cpp index dcac6d11d..cab2c954b 100644 --- a/src/tokenize.cpp +++ b/src/tokenize.cpp @@ -3408,7 +3408,7 @@ bool Tokenizer::simplifyRedundantParanthesis() ret = true; } - if (Token::Match(tok->previous(), "[(!*;] ( %var% )") && tok->next()->varId() != 0) + if (Token::Match(tok->previous(), "[(!*;}] ( %var% )") && tok->next()->varId() != 0) { // We have "( var )", remove the paranthesis tok = tok->previous(); diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index f22caaaf8..f260d28f8 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -421,6 +421,7 @@ private: ASSERT_EQUALS("void f ( ) { int p [ 10 ] ; p [ 0 ] = 1 ; }", tok("void f(){int p[10]; (p)[0] = 1;}")); ASSERT_EQUALS("void f ( ) { int p ; if ( ! p ) { } }", tok("void f(){int p; if ((p) == 0) {}}")); ASSERT_EQUALS("void f ( ) { int * p ; * p = 1 ; }", tok("void f(){int *p; *(p) = 1;}")); + ASSERT_EQUALS("void f ( ) { int p ; if ( p ) { } p = 1 ; }", tok("void f(){int p; if ( p ) { } (p) = 1;}")); // keep parantheses.. ASSERT_EQUALS("= a ;", tok("= (char)a;"));