diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 60a4d79ac..bf576d943 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -407,6 +407,10 @@ bool Tokenizer::duplicateTypedef(Token **tokPtr, const Token *name) } else if (end->str() == ",") { + // check for derived class + if (Token::Match(tok->previous(), "public|private|protected")) + return false; + // find end of definition int level = 0; while (end && end->next() && (!Token::Match(end->next(), ";|)|>") || @@ -439,7 +443,7 @@ bool Tokenizer::duplicateTypedef(Token **tokPtr, const Token *name) { // look backwards if (Token::Match(tok->previous(), "%type%") && - !Token::Match(tok->previous(), "return|new|const")) + !Token::Match(tok->previous(), "return|new|const|volatile")) { // duplicate definition so skip entire template while (end && end->str() != "{") diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 207656130..9961eecd9 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -174,6 +174,8 @@ private: TEST_CASE(simplifyTypedef35); TEST_CASE(simplifyTypedef36); // ticket #1434 TEST_CASE(simplifyTypedef37); // ticket #1449 + TEST_CASE(simplifyTypedef38); + TEST_CASE(simplifyTypedef39); TEST_CASE(reverseArraySyntax) TEST_CASE(simplify_numeric_condition) @@ -3394,6 +3396,28 @@ private: } } + void simplifyTypedef38() + { + const char code[] = "typedef C A;\n" + "struct AB : public A, public B { };"; + const char expected[] = "; struct AB : public C , public B { } ;"; + ASSERT_EQUALS(expected, tok(code, false)); + + checkSimplifyTypedef(code); + ASSERT_EQUALS("", errout.str()); + } + + void simplifyTypedef39() + { + const char code[] = "typedef int A;\n" + "template ::value;"; + const char expected[] = "; ;"; + ASSERT_EQUALS(expected, tok(code, false)); + + checkSimplifyTypedef(code); + ASSERT_EQUALS("", errout.str()); + } + void reverseArraySyntax() { ASSERT_EQUALS("a [ 13 ]", tok("13[a]"));