Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #12312 FP variableScope with templates in namespace #6167

Merged
merged 2 commits into from
Mar 29, 2024
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
2 changes: 1 addition & 1 deletion lib/templatesimplifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2172,7 +2172,7 @@ void TemplateSimplifier::expandTemplate(
addNamespace(templateDeclaration, tok3);
}
mTokenList.addtoken(newName, tok3);
} else if (!Token::Match(tok3->next(), ":|{|=|;|[|]"))
} else if (!Token::Match(tok3->next(), "[:{=;[]),]"))
tok3->str(newName);
continue;
}
Expand Down
19 changes: 19 additions & 0 deletions test/testsimplifytemplate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ class TestSimplifyTemplate : public TestFixture {
TEST_CASE(template178);
TEST_CASE(template_specialization_1); // #7868 - template specialization template <typename T> struct S<C<T>> {..};
TEST_CASE(template_specialization_2); // #7868 - template specialization template <typename T> struct S<C<T>> {..};
TEST_CASE(template_specialization_3);
TEST_CASE(template_enum); // #6299 Syntax error in complex enum declaration (including template)
TEST_CASE(template_unhandled);
TEST_CASE(template_default_parameter);
Expand Down Expand Up @@ -4564,6 +4565,24 @@ class TestSimplifyTemplate : public TestFixture {
ASSERT_EQUALS(exp, tok(code));
}

void template_specialization_3() {
const char code[] = "namespace N {\n" // #12312
" template <typename T>\n"
" bool equal(const T&);\n"
" template <>\n"
" bool equal<int>(const int&) { return false; }\n"
"}\n"
"void f(bool equal, int i) { if (equal) {} }\n";
const char exp[] = "namespace N { "
"bool equal<int> ( const int & ) ; "
"template < typename T > "
"bool equal ( const T & ) ; "
"bool equal<int> ( const int & ) { return false ; } "
"} "
"void f ( bool equal , int i ) { if ( equal ) { } }";
ASSERT_EQUALS(exp, tok(code));
}

void template_enum() {
const char code1[] = "template <class T>\n"
"struct Unconst {\n"
Expand Down
Loading