Skip to content

Commit 8e79e5c

Browse files
committed
Fixed cppcheck-opensource#7147 (TemplateSimplifier: specialized template class with inheritance)
1 parent e03e9fb commit 8e79e5c

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

lib/templatesimplifier.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ std::set<std::string> TemplateSimplifier::expandSpecialized(Token *tokens)
430430
ostr << " ";
431431
ostr << tok3->str();
432432
}
433-
if (!Token::Match(tok3, "> (|{"))
433+
if (!Token::Match(tok3, "> (|{|:"))
434434
continue;
435435
s = ostr.str();
436436
}

test/testsimplifytemplate.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ class TestSimplifyTemplate : public TestFixture {
101101
TEST_CASE(templateParameters);
102102

103103
TEST_CASE(templateNamePosition);
104+
105+
TEST_CASE(expandSpecialized);
104106
}
105107

106108
std::string tok(const char code[], bool simplify = true, bool debugwarnings = false, Settings::PlatformType type = Settings::Native) {
@@ -1318,6 +1320,11 @@ class TestSimplifyTemplate : public TestFixture {
13181320
TODO_ASSERT_EQUALS(7, -1, templateNamePositionHelper("template<class T> class A { unsigned foo(); }; "
13191321
"template<class T> unsigned A<T>::foo() { return 0; }", 19));
13201322
}
1323+
1324+
void expandSpecialized() {
1325+
ASSERT_EQUALS("class A<int> { } ;", tok("template<> class A<int> {};"));
1326+
ASSERT_EQUALS("class A<int> : public B { } ;", tok("template<> class A<int> : public B {};"));
1327+
}
13211328
};
13221329

13231330
REGISTER_TEST(TestSimplifyTemplate)

0 commit comments

Comments
 (0)