Don't simplify template for class names in declarations (#3505)
* Don't simplify template for class names in declarations Without the patch, the test would give: ``` Expected: namespace foo { class Bar ; } class Baz ; class C : Baz { } ; Actual: namespace foo { class Bar ; } class Baz ; class foo :: Bar : Baz { } ; ``` * Use valid code in test case
This commit is contained in:
parent
ffc2a9d8e2
commit
f5f600bafc
|
@ -1167,6 +1167,10 @@ void Tokenizer::simplifyTypedef()
|
|||
}
|
||||
}
|
||||
|
||||
else if (Token::Match(tok2->previous(), "class|struct %name% [:{]")) {
|
||||
// don't replace names in struct/class definition
|
||||
}
|
||||
|
||||
// check for typedef that can be substituted
|
||||
else if ((tok2->isNameOnly() || (tok2->isName() && tok2->isExpandedMacro())) &&
|
||||
(Token::simpleMatch(tok2, pattern.c_str(), pattern.size()) ||
|
||||
|
|
|
@ -181,6 +181,7 @@ private:
|
|||
TEST_CASE(simplifyTypedef135); // ticket #10068
|
||||
TEST_CASE(simplifyTypedef136);
|
||||
TEST_CASE(simplifyTypedef137);
|
||||
TEST_CASE(simplifyTypedef138);
|
||||
|
||||
TEST_CASE(simplifyTypedefFunction1);
|
||||
TEST_CASE(simplifyTypedefFunction2); // ticket #1685
|
||||
|
@ -2997,6 +2998,16 @@ private:
|
|||
}
|
||||
}
|
||||
|
||||
void simplifyTypedef138() {
|
||||
const char code[] = "namespace foo { class Bar; }\n"
|
||||
"class Baz;\n"
|
||||
"typedef foo::Bar C;\n"
|
||||
"namespace bar {\n"
|
||||
"class C : Baz {};\n"
|
||||
"}\n";
|
||||
ASSERT_EQUALS("namespace foo { class Bar ; } class Baz ; namespace bar { class C : Baz { } ; }", tok(code));
|
||||
}
|
||||
|
||||
void simplifyTypedefFunction1() {
|
||||
{
|
||||
const char code[] = "typedef void (*my_func)();\n"
|
||||
|
|
Loading…
Reference in New Issue