Skip to content

Commit f5f600b

Browse files
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
1 parent ffc2a9d commit f5f600b

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

lib/tokenize.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,6 +1167,10 @@ void Tokenizer::simplifyTypedef()
11671167
}
11681168
}
11691169

1170+
else if (Token::Match(tok2->previous(), "class|struct %name% [:{]")) {
1171+
// don't replace names in struct/class definition
1172+
}
1173+
11701174
// check for typedef that can be substituted
11711175
else if ((tok2->isNameOnly() || (tok2->isName() && tok2->isExpandedMacro())) &&
11721176
(Token::simpleMatch(tok2, pattern.c_str(), pattern.size()) ||

test/testsimplifytypedef.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ class TestSimplifyTypedef : public TestFixture {
181181
TEST_CASE(simplifyTypedef135); // ticket #10068
182182
TEST_CASE(simplifyTypedef136);
183183
TEST_CASE(simplifyTypedef137);
184+
TEST_CASE(simplifyTypedef138);
184185

185186
TEST_CASE(simplifyTypedefFunction1);
186187
TEST_CASE(simplifyTypedefFunction2); // ticket #1685
@@ -2997,6 +2998,16 @@ class TestSimplifyTypedef : public TestFixture {
29972998
}
29982999
}
29993000

3001+
void simplifyTypedef138() {
3002+
const char code[] = "namespace foo { class Bar; }\n"
3003+
"class Baz;\n"
3004+
"typedef foo::Bar C;\n"
3005+
"namespace bar {\n"
3006+
"class C : Baz {};\n"
3007+
"}\n";
3008+
ASSERT_EQUALS("namespace foo { class Bar ; } class Baz ; namespace bar { class C : Baz { } ; }", tok(code));
3009+
}
3010+
30003011
void simplifyTypedefFunction1() {
30013012
{
30023013
const char code[] = "typedef void (*my_func)();\n"

0 commit comments

Comments
 (0)