Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1389,7 +1389,7 @@ void Tokenizer::simplifyTypedef()

// skip over class or struct in derived class declaration
bool structRemoved = false;
if (isDerived && Token::Match(typeStart, "class|struct")) {
if ((isDerived || inTemplate) && Token::Match(typeStart, "class|struct")) {
if (typeStart->str() == "struct")
structRemoved = true;
typeStart = typeStart->next();
Expand Down
16 changes: 16 additions & 0 deletions test/testcondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4947,6 +4947,22 @@ class TestCondition : public TestFixture {
" buffer.back() == '\\0') {}\n"
"}\n");
ASSERT_EQUALS("[test.cpp:5]: (style) Condition 'buffer.back()=='\\0'' is always false\n", errout.str());

// #9353
check("typedef struct { std::string s; } X;\n"
"void f(const std::vector<X>&v) {\n"
" for (std::vector<X>::const_iterator it = v.begin(); it != v.end(); ++it)\n"
" if (!it->s.empty()) {\n"
" if (!it->s.empty()) {}\n"
" }\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:5]: (style) Condition '!it->s.empty()' is always true\n", errout.str());

// #10508
check("bool f(const std::string& a, const std::string& b) {\n"
" return a.empty() || (b.empty() && a.empty());\n"
"}\n");
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2]: (style) Return value 'a.empty()' is always false\n", errout.str());
}

void alwaysTrueLoop()
Expand Down
7 changes: 7 additions & 0 deletions test/testsimplifytypedef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ class TestSimplifyTypedef : public TestFixture {
TEST_CASE(simplifyTypedef140); // #10798
TEST_CASE(simplifyTypedef141); // #10144
TEST_CASE(simplifyTypedef142); // T() when T is a pointer type
TEST_CASE(simplifyTypedef144); // #9353

TEST_CASE(simplifyTypedefFunction1);
TEST_CASE(simplifyTypedefFunction2); // ticket #1685
Expand Down Expand Up @@ -3070,6 +3071,12 @@ class TestSimplifyTypedef : public TestFixture {
ASSERT_EQUALS("void f ( int * = ( int * ) 0 ) { }", tok(code2));
}

void simplifyTypedef144() { // #9353
const char code[] = "typedef struct {} X;\n"
"std::vector<X> v;\n";
ASSERT_EQUALS("struct X { } ; std :: vector < X > v ;", tok(code));
}

void simplifyTypedefFunction1() {
{
const char code[] = "typedef void (*my_func)();\n"
Expand Down