Skip to content

Commit bc2c172

Browse files
committed
Merge pull request cppcheck-opensource#607 from simartin/simplify_known_var_todo
Simplify known variables when they are at the end of a statement.
2 parents 5fa2fe0 + 85b4763 commit bc2c172

2 files changed

Lines changed: 6 additions & 8 deletions

File tree

lib/tokenize.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6732,9 +6732,9 @@ bool Tokenizer::simplifyKnownVariablesSimplify(Token **tok2, Token *tok3, unsign
67326732
ret = true;
67336733
}
67346734

6735-
// condition "(|&&|%OROR% %varid% )|&&|%OROR%
6735+
// condition "(|&&|%OROR% %varid% )|&&|%OROR%|;
67366736
if (!Token::Match(tok3->previous(), "( %name% )") &&
6737-
Token::Match(tok3->previous(), "&&|(|%oror% %varid% &&|%oror%|)", varid)) {
6737+
Token::Match(tok3->previous(), "&&|(|%oror% %varid% &&|%oror%|)|;", varid)) {
67386738
tok3->str(value);
67396739
tok3->varId(valueVarId);
67406740
ret = true;

test/testtokenize.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2231,8 +2231,7 @@ class TestTokenizer : public TestFixture {
22312231
"4:\n"
22322232
"5: return u@1 && v@2 ;\n"
22332233
"6: }\n";
2234-
const char current[] = "\n\n##file 0\n1: bool foo ( int u@1 , int v@2 )\n2: {\n3:\n4: int i@4 ; i@4 = v@2 ;\n5: return u@1 && i@4 ;\n6: }\n";
2235-
TODO_ASSERT_EQUALS(wanted, current, tokenizeDebugListing(code, true));
2234+
ASSERT_EQUALS(wanted, tokenizeDebugListing(code, true));
22362235
}
22372236

22382237
{
@@ -2245,12 +2244,11 @@ class TestTokenizer : public TestFixture {
22452244
const char wanted[] = "\n\n##file 0\n"
22462245
"1: bool foo ( int u@1 , int v@2 )\n"
22472246
"2: {\n"
2248-
"3: ;\n"
2249-
"4: ;\n"
2247+
"3:\n"
2248+
"4:\n"
22502249
"5: return u@1 || v@2 ;\n"
22512250
"6: }\n";
2252-
const char current[] = "\n\n##file 0\n1: bool foo ( int u@1 , int v@2 )\n2: {\n3:\n4: int i@4 ; i@4 = v@2 ;\n5: return u@1 || i@4 ;\n6: }\n";
2253-
TODO_ASSERT_EQUALS(wanted, current, tokenizeDebugListing(code, true));
2251+
ASSERT_EQUALS(wanted, tokenizeDebugListing(code, true));
22542252
}
22552253
}
22562254

0 commit comments

Comments
 (0)