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:
KenPatrickLehrmann 2021-11-06 19:07:45 +01:00 committed by GitHub
parent ffc2a9d8e2
commit f5f600bafc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 0 deletions

View File

@ -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()) ||

View File

@ -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"