Skip to content

Commit 2bfeef0

Browse files
Add tests for #10811, #11046, remove dead code (#6458)
1 parent ab9def9 commit 2bfeef0

2 files changed

Lines changed: 18 additions & 6 deletions

File tree

lib/tokenize.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8782,12 +8782,8 @@ void Tokenizer::findGarbageCode() const
87828782
// Garbage templates..
87838783
if (isCPP()) {
87848784
for (const Token *tok = tokens(); tok; tok = tok->next()) {
8785-
if (Token::simpleMatch(tok, "< >")) {
8786-
if (!(Token::Match(tok->tokAt(-1), "%name%") || (tok->tokAt(-1) && Token::Match(tok->tokAt(-2), "operator %op%"))))
8787-
syntaxError(tok);
8788-
if (!tok->tokAt(-1) || tok->tokAt(-1)->isLiteral())
8789-
syntaxError(tok);
8790-
}
8785+
if (Token::simpleMatch(tok, "< >") && !(Token::Match(tok->tokAt(-1), "%name%") || (tok->tokAt(-1) && Token::Match(tok->tokAt(-2), "operator %op%"))))
8786+
syntaxError(tok);
87918787
if (!Token::simpleMatch(tok, "template <"))
87928788
continue;
87938789
if (!tok->tokAt(2) || tok->tokAt(2)->isLiteral())

test/testcondition.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4584,6 +4584,22 @@ class TestCondition : public TestFixture {
45844584
" return 1;\n"
45854585
"}\n");
45864586
ASSERT_EQUALS("", errout_str());
4587+
4588+
check("namespace S { int s{}; };\n" // #11046
4589+
"void f(bool b) {\n"
4590+
" if (S::s) {\n"
4591+
" if (b) {\n"
4592+
" if (S::s) {}\n"
4593+
" }\n"
4594+
" }\n"
4595+
"}\n");
4596+
ASSERT_EQUALS("[test.cpp:5]: (style) Condition 'S::s' is always true\n", errout_str());
4597+
4598+
check("void f() {\n" // #10811
4599+
" int i = 0;\n"
4600+
" if ((i = g(), 1) != 0) {}\n"
4601+
"}\n");
4602+
ASSERT_EQUALS("[test.cpp:3]: (style) Condition '(i=g(),1)!=0' is always true\n", errout_str());
45874603
}
45884604

45894605
void alwaysTrueSymbolic()

0 commit comments

Comments
 (0)