Skip to content

Commit a55b557

Browse files
Fix #13725 Bad varid for nested class member (#7388)
1 parent 3253e48 commit a55b557

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

lib/tokenize.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -4425,6 +4425,10 @@ static bool setVarIdClassDeclaration(Token* const startToken,
44254425
}
44264426
if (tok->str() == "{") {
44274427
inEnum = isEnumStart(tok);
4428+
if (!inEnum && isClassStructUnionEnumStart(tok)) { // nested type
4429+
tok = tok->link();
4430+
continue;
4431+
}
44284432
if (initList && !initListArgLastToken)
44294433
initList = false;
44304434
++indentlevel;

test/testvarid.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ class TestVarID : public TestFixture {
150150
TEST_CASE(varid_in_class25);
151151
TEST_CASE(varid_in_class26);
152152
TEST_CASE(varid_in_class27);
153+
TEST_CASE(varid_in_class28);
153154
TEST_CASE(varid_namespace_1); // #7272
154155
TEST_CASE(varid_namespace_2); // #7000
155156
TEST_CASE(varid_namespace_3); // #8627
@@ -2346,6 +2347,22 @@ class TestVarID : public TestFixture {
23462347
ASSERT_EQUALS(expected, tokenize(code));
23472348
}
23482349

2350+
void varid_in_class28() {
2351+
const char code[] = "struct S {\n" // 13725
2352+
" struct T {\n"
2353+
" bool b();\n"
2354+
" };\n"
2355+
" bool b = false;\n"
2356+
"};\n";
2357+
const char expected[] = "1: struct S {\n"
2358+
"2: struct T {\n"
2359+
"3: bool b ( ) ;\n"
2360+
"4: } ;\n"
2361+
"5: bool b@1 ; b@1 = false ;\n"
2362+
"6: } ;\n";
2363+
ASSERT_EQUALS(expected, tokenize(code));
2364+
}
2365+
23492366
void varid_namespace_1() { // #7272
23502367
const char code[] = "namespace Blah {\n"
23512368
" struct foo { int x;};\n"

0 commit comments

Comments
 (0)