diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index d88610b731a..166662622a3 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -6339,10 +6339,16 @@ void Tokenizer::simplifyHeadersAndUnusedTemplates() } const std::set functionStart{"static", "const", "unsigned", "signed", "void", "bool", "char", "short", "int", "long", "float", "*"}; + bool goBack = false; for (Token *tok = list.front(); tok; tok = tok->next()) { const bool isIncluded = (tok->fileIndex() != 0); + if (goBack) { + tok = tok->previous(); + } + goBack = false; + // Remove executable code if (isIncluded && !mSettings.checkHeaders && tok->str() == "{") { // 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() const Token *endToken = closingBracket->linkAt(3)->linkAt(1)->next(); Token::eraseTokens(tok, endToken); tok->deleteThis(); + goBack = true; } } } diff --git a/test/cli/other_test.py b/test/cli/other_test.py index ec73fef11e3..a747493e48d 100644 --- a/test/cli/other_test.py +++ b/test/cli/other_test.py @@ -3130,7 +3130,6 @@ class Cl2 assert stderr.splitlines() == [] # no error since the unused templates are not being checked -@pytest.mark.xfail(strict=True) # TODO: only the first unused templated function is not being checked def test_check_unused_templates_func(tmp_path): # #13714 test_file_h = tmp_path / 'test.h' with open(test_file_h, 'wt') as f: