Skip to content
Open
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
9 changes: 8 additions & 1 deletion lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3201,8 +3201,15 @@ bool Tokenizer::simplifyUsing()
continue;
}

// skip template definitions
if (Token::Match(tok1, "template < !!>")) {
Token *paramsEnd = tok1->next()->findClosingBracket();
Comment thread
chrchr-github marked this conversation as resolved.
bool shadowed = !paramsEnd;
for (const Token *param = tok1->next(); !shadowed && param != paramsEnd; param = param->next())
shadowed = param->str() == nameToken->str();
if (!shadowed) {
tok1 = paramsEnd;
continue;
}
Token *declEndToken = TemplateSimplifier::findTemplateDeclarationEnd(tok1);
if (declEndToken)
tok1 = declEndToken;
Expand Down
35 changes: 35 additions & 0 deletions test/testsimplifyusing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class TestSimplifyUsing : public TestFixture {
TEST_CASE(simplifyUsing39);
TEST_CASE(simplifyUsing40);
TEST_CASE(simplifyUsing41);
TEST_CASE(simplifyUsing42);
Comment thread
ludviggunne marked this conversation as resolved.

TEST_CASE(simplifyUsing8970);
TEST_CASE(simplifyUsing8971);
Expand Down Expand Up @@ -956,6 +957,40 @@ class TestSimplifyUsing : public TestFixture {
ASSERT_EQUALS(expected, tok(code));
}

void simplifyUsing42() {
{
const char code[] = "using A = bool;\n"
"template<typename T> A func() {}\n";
const char expected[] = "template < typename T > bool func ( ) { }";
ASSERT_EQUALS(expected, tok(code));
}
{
const char code[] = "using A = bool;\n"
"template<typename A> A func() {}\n";
const char expected[] = "template < typename A > A func ( ) { }";
ASSERT_EQUALS(expected, tok(code));
}
{
const char code[] = "using A = bool;\n"
"template<typename T> class C { A x; }\n";
const char expected[] = "template < typename T > class C { bool x ; }";
ASSERT_EQUALS(expected, tok(code));
}
{
const char code[] = "using A = bool;\n"
"template<typename A> class C { A x; }\n";
const char expected[] = "template < typename A > class C { A x ; }";
ASSERT_EQUALS(expected, tok(code));
}
{
const char code[] = "using A = bool;\n"
"template<typename T> class C { using A = T; A x; }\n"
"C<int> c;\n";
const char expected[] = "class C<int> ; C<int> c ; class C<int> { int x ; }";
ASSERT_EQUALS(expected, tok(code));
}
}

void simplifyUsing8970() {
const char code[] = "using V = std::vector<int>;\n"
"struct A {\n"
Expand Down
Loading