Skip to content

Commit

Permalink
Fix handling curled braces and multiple variables
Browse files Browse the repository at this point in the history
  • Loading branch information
RobkeBaer committed May 3, 2024
1 parent b30aa4c commit 8bc47d8
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 7 deletions.
22 changes: 19 additions & 3 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6229,10 +6229,26 @@ void Tokenizer::simplifyHeadersAndUnusedTemplates()
if (isIncluded && !mSettings.checkHeaders && tok->str() == ":") {
if (tok->previous() && tok->previous()->str() == ")") {
const Token *next = tok->next();
while (next && next->str() != "{")
//Skip over firts name
while (next && !next->link())
next = next->next();
Token::eraseTokens(tok, next);
tok->deleteThis();
if (next) {
next = next->link();
next = next->next();
//Skip over all following elements that start with , (still part of the initializer)
while (next && next->str() == ",") {
while (next && !next->link())
next = next->next();
if (next) {
next = next->link();
next = next->next();
}
}
if (next){
Token::eraseTokens(tok, next);
tok->deleteThis();
}
}
}
}

Expand Down
35 changes: 31 additions & 4 deletions test/testtokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ class TestTokenizer : public TestFixture {

TEST_CASE(checkHeader1);
TEST_CASE(checkHeader2);
TEST_CASE(checkHeader3);

TEST_CASE(removeExtraTemplateKeywords);

Expand Down Expand Up @@ -7755,19 +7756,45 @@ class TestTokenizer : public TestFixture {
// #9977
const char code[] = "# 1 \"test.h\"\n"
"A::A(const int &value)\n"
" :data(value)\n"
" :data(value),\n"
" data2(value)\n"
" {}\n";

ASSERT_EQUALS("\n\n##file 1\n"
"1: A :: A ( const int & value )\n"
"2: : data ( value )\n"
"3: { }\n",
"2: : data ( value ) ,\n"
"3: data2 ( value )\n"
"4: { }\n",
checkHdrs(code, true));

ASSERT_EQUALS("\n\n##file 1\n"
"1: A :: A ( const int & value )\n"
"2:\n"
"3: ;\n",
"3:\n"
"4: ;\n",
checkHdrs(code, false));
}

void checkHeader3() {
// #9977
const char code[] = "# 1 \"test.h\"\n"
"A::A(const int &value)\n"
" :data{value},\n"
" data2{value}\n"
" {}\n";

ASSERT_EQUALS("\n\n##file 1\n"
"1: A :: A ( const int & value )\n"
"2: : data { value } ,\n"
"3: data2 { value }\n"
"4: { }\n",
checkHdrs(code, true));

ASSERT_EQUALS("\n\n##file 1\n"
"1: A :: A ( const int & value )\n"
"2:\n"
"3:\n"
"4: ;\n",
checkHdrs(code, false));
}

Expand Down

0 comments on commit 8bc47d8

Please sign in to comment.