Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/templatesimplifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2061,7 +2061,14 @@ void TemplateSimplifier::expandTemplate(
const std::string lastName = (templateInstantiation.name().find(' ') != std::string::npos) ? templateInstantiation.name().substr(templateInstantiation.name().rfind(' ')+1) : templateInstantiation.name();

std::stack<const Token *> templates;
int scopeCount = 0;
for (; tok3; tok3 = tok3->next()) {
if (tok3->str() == "{")
++scopeCount;
else if (tok3->str() == "}")
--scopeCount;
if (scopeCount < 0)
break;
if (tok3->isName() && !Token::Match(tok3, "class|typename|struct") && !tok3->isStandardType()) {
// search for this token in the type vector
unsigned int itype = 0;
Expand Down
22 changes: 22 additions & 0 deletions test/testsimplifytemplate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ class TestSimplifyTemplate : public TestFixture {
TEST_CASE(template_namespace_9);
TEST_CASE(template_namespace_10);
TEST_CASE(template_namespace_11); // #7145
TEST_CASE(template_namespace_12);
TEST_CASE(template_pointer_type);
TEST_CASE(template_array_type);

Expand Down Expand Up @@ -5264,6 +5265,27 @@ class TestSimplifyTemplate : public TestFixture {
"} int MyNamespace :: TestClass :: TemplatedMethod<int> ( int t ) { return t ; }", tok(code));
}

void template_namespace_12() {
const char code[] = "struct S {};\n" // #13444
"namespace N {\n"
" template<>\n"
" struct hash<S> {};\n"
"}\n"
"struct T {\n"
" T(int i) : hash(i) {}\n"
" int hash;\n"
"};\n";
ASSERT_EQUALS("struct S { } ; "
"namespace N { "
"struct hash<S> { } ; "
"} "
"struct T { "
"T ( int i ) : hash ( i ) { } "
"int hash ; "
"} ;",
tok(code));
}

void template_pointer_type() {
const char code[] = "template<class T> void foo(const T x) {}\n"
"void bar() { foo<int*>(0); }";
Expand Down