Skip to content

Commit a150ff4

Browse files
Fix #14486 FP selfInitialization with local class derived from template (#8208)
1 parent 781277c commit a150ff4

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

lib/tokenize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ static bool isClassStructUnionEnumStart(const Token * tok)
108108
if (!Token::Match(tok->previous(), "class|struct|union|enum|%name%|>|>> {"))
109109
return false;
110110
const Token * tok2 = tok->previous();
111-
while (tok2 && !Token::Match(tok2, "class|struct|union|enum|{|}|)|;|>|>>"))
111+
while (tok2 && !Token::Match(tok2, "class|struct|union|enum|{|}|)|;"))
112112
tok2 = tok2->previous();
113113
return Token::Match(tok2, "class|struct|union|enum") && !Token::simpleMatch(tok2->tokAt(-1), "->");
114114
}

test/testvarid.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ class TestVarID : public TestFixture {
149149
TEST_CASE(varid_in_class26);
150150
TEST_CASE(varid_in_class27);
151151
TEST_CASE(varid_in_class28);
152+
TEST_CASE(varid_in_class29);
152153
TEST_CASE(varid_namespace_1); // #7272
153154
TEST_CASE(varid_namespace_2); // #7000
154155
TEST_CASE(varid_namespace_3); // #8627
@@ -2380,6 +2381,28 @@ class TestVarID : public TestFixture {
23802381
ASSERT_EQUALS(expected, tokenize(code));
23812382
}
23822383

2384+
void varid_in_class29() {
2385+
const char code[] = "struct S {\n" // #14486
2386+
" const int& r;\n"
2387+
" explicit S(const int& r) : r(r) {}\n"
2388+
" static void f() {\n"
2389+
" struct T : std::vector<int> {\n"
2390+
" bool g() const { return empty(); }\n"
2391+
" };\n"
2392+
" }\n"
2393+
"};\n";
2394+
const char expected[] = "1: struct S {\n"
2395+
"2: const int & r@1 ;\n"
2396+
"3: explicit S ( const int & r@2 ) : r@1 ( r@2 ) { }\n"
2397+
"4: static void f ( ) {\n"
2398+
"5: struct T : std :: vector < int > {\n"
2399+
"6: bool g ( ) const { return empty ( ) ; }\n"
2400+
"7: } ;\n"
2401+
"8: }\n"
2402+
"9: } ;\n";
2403+
ASSERT_EQUALS(expected, tokenize(code));
2404+
}
2405+
23832406
void varid_namespace_1() { // #7272
23842407
const char code[] = "namespace Blah {\n"
23852408
" struct foo { int x;};\n"

0 commit comments

Comments
 (0)