Skip to content

Commit 2c2342f

Browse files
authored
fix #13714: only the first unused templated function is not being checked with --no-check-unused-templates (#7802)
1 parent 08272b3 commit 2c2342f

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/tokenize.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6339,10 +6339,16 @@ void Tokenizer::simplifyHeadersAndUnusedTemplates()
63396339
}
63406340

63416341
const std::set<std::string> functionStart{"static", "const", "unsigned", "signed", "void", "bool", "char", "short", "int", "long", "float", "*"};
6342+
bool goBack = false;
63426343

63436344
for (Token *tok = list.front(); tok; tok = tok->next()) {
63446345
const bool isIncluded = (tok->fileIndex() != 0);
63456346

6347+
if (goBack) {
6348+
tok = tok->previous();
6349+
}
6350+
goBack = false;
6351+
63466352
// Remove executable code
63476353
if (isIncluded && !mSettings.checkHeaders && tok->str() == "{") {
63486354
// TODO: We probably need to keep the executable code if this function is called from the source file.
@@ -6408,6 +6414,7 @@ void Tokenizer::simplifyHeadersAndUnusedTemplates()
64086414
const Token *endToken = closingBracket->linkAt(3)->linkAt(1)->next();
64096415
Token::eraseTokens(tok, endToken);
64106416
tok->deleteThis();
6417+
goBack = true;
64116418
}
64126419
}
64136420
}

test/cli/other_test.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3130,7 +3130,6 @@ class Cl2
31303130
assert stderr.splitlines() == [] # no error since the unused templates are not being checked
31313131

31323132

3133-
@pytest.mark.xfail(strict=True) # TODO: only the first unused templated function is not being checked
31343133
def test_check_unused_templates_func(tmp_path): # #13714
31353134
test_file_h = tmp_path / 'test.h'
31363135
with open(test_file_h, 'wt') as f:

0 commit comments

Comments
 (0)