Skip to content

Commit e7bdf5f

Browse files
IOBYTERobert Reif
andauthored
remove cleanupAfterSimplify from the template simplifier (#2998)
The template simplifier works well enough now so cleanupAfterSimplify is no longer necessary. In fact cleanupAfterSimplify was introducing a bug which improperly simplified C++ style casts. Bugs should be exposed and fixed properly rather than just hiding them. Co-authored-by: Robert Reif <reif@FX6840>
1 parent d99f17b commit e7bdf5f

6 files changed

Lines changed: 6 additions & 69 deletions

File tree

lib/checksizeof.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ void CheckSizeof::sizeofCalculation()
296296
if (tok->isExpandedMacro() && tok->previous()) {
297297
const Token *cast_end = (tok->previous()->str() == "(") ? tok->previous() : tok;
298298
if (Token::simpleMatch(cast_end->tokAt(-3), "( void )") ||
299-
Token::simpleMatch(cast_end->previous(), "static_cast<void>")) {
299+
Token::simpleMatch(cast_end->tokAt(-4), "static_cast < void >")) {
300300
continue;
301301
}
302302
}
@@ -337,7 +337,7 @@ void CheckSizeof::sizeofFunction()
337337
if (tok->isExpandedMacro() && tok->previous()) {
338338
const Token *cast_end = (tok->previous()->str() == "(") ? tok->previous() : tok;
339339
if (Token::simpleMatch(cast_end->tokAt(-3), "( void )") ||
340-
Token::simpleMatch(cast_end->previous(), "static_cast<void>")) {
340+
Token::simpleMatch(cast_end->tokAt(-4), "static_cast < void >")) {
341341
continue;
342342
}
343343
}

lib/templatesimplifier.cpp

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -245,58 +245,6 @@ TemplateSimplifier::~TemplateSimplifier()
245245
{
246246
}
247247

248-
void TemplateSimplifier::cleanupAfterSimplify()
249-
{
250-
bool goback = false;
251-
for (Token *tok = mTokenList.front(); tok; tok = tok->next()) {
252-
if (goback) {
253-
tok = tok->previous();
254-
goback = false;
255-
}
256-
if (tok->str() == "(")
257-
tok = tok->link();
258-
259-
else if (Token::Match(tok, "template < > %name%")) {
260-
const Token *end = tok;
261-
while (end) {
262-
if (end->str() == ";")
263-
break;
264-
if (end->str() == "{") {
265-
end = end->link()->next();
266-
break;
267-
}
268-
if (!Token::Match(end, "%name%|::|<|>|,")) {
269-
end = nullptr;
270-
break;
271-
}
272-
end = end->next();
273-
}
274-
if (end) {
275-
Token::eraseTokens(tok,end);
276-
tok->deleteThis();
277-
}
278-
}
279-
280-
else if (Token::Match(tok, "%type% <") &&
281-
(!tok->previous() || tok->previous()->str() == ";")) {
282-
const Token *tok2 = tok->tokAt(2);
283-
std::string type;
284-
while (Token::Match(tok2, "%type%|%num% ,")) {
285-
type += tok2->str() + ",";
286-
tok2 = tok2->tokAt(2);
287-
}
288-
if (Token::Match(tok2, "%type%|%num% > (")) {
289-
type += tok2->str();
290-
tok->str(tok->str() + "<" + type + ">");
291-
Token::eraseTokens(tok, tok2->tokAt(2));
292-
if (tok == mTokenList.front())
293-
goback = true;
294-
}
295-
}
296-
}
297-
}
298-
299-
300248
void TemplateSimplifier::checkComplicatedSyntaxErrorsInTemplates()
301249
{
302250
// check for more complicated syntax errors when using templates..

lib/templatesimplifier.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,6 @@ class CPPCHECKLIB TemplateSimplifier {
4747
explicit TemplateSimplifier(Tokenizer *tokenizer);
4848
~TemplateSimplifier();
4949

50-
/**
51-
* Used after simplifyTemplates to perform a little cleanup.
52-
* Sometimes the simplifyTemplates isn't fully successful and then
53-
* there are function calls etc with "wrong" syntax.
54-
*/
55-
void cleanupAfterSimplify();
56-
5750
/**
5851
*/
5952
void checkComplicatedSyntaxErrorsInTemplates();

lib/tokenize.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4747,11 +4747,7 @@ bool Tokenizer::simplifyTokenList1(const char FileName[])
47474747
if (Settings::terminated())
47484748
return false;
47494749

4750-
// sometimes the "simplifyTemplates" fail and then unsimplified
4751-
// function calls etc remain. These have the "wrong" syntax. So
4752-
// this function will just fix so that the syntax is corrected.
47534750
validate(); // #6847 - invalid code
4754-
mTemplateSimplifier->cleanupAfterSimplify();
47554751
}
47564752

47574753
// Simplify pointer to standard types (C only)

test/testsimplifytemplate.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -997,8 +997,8 @@ class TestSimplifyTemplate : public TestFixture {
997997
}
998998

999999
void template_unhandled() {
1000-
// An unhandled template usage should be simplified..
1001-
ASSERT_EQUALS("x<int> ( ) ;", tok("x<int>();"));
1000+
// An unhandled template usage should not be simplified..
1001+
ASSERT_EQUALS("x < int > ( ) ;", tok("x<int>();"));
10021002
}
10031003

10041004
void template38() { // #4832 - Crash on C++11 right angle brackets

test/testtokenize.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4315,13 +4315,13 @@ class TestTokenizer : public TestFixture {
43154315
void unsigned3() {
43164316
{
43174317
const char code[] = "; foo<unsigned>();";
4318-
const char expected[] = "; foo<int> ( ) ;";
4318+
const char expected[] = "; foo < unsigned int > ( ) ;";
43194319
ASSERT_EQUALS(expected, tokenizeAndStringify(code));
43204320
}
43214321

43224322
{
43234323
const char code[] = "; foo<unsigned int>();";
4324-
const char expected[] = "; foo<int> ( ) ;";
4324+
const char expected[] = "; foo < unsigned int > ( ) ;";
43254325
ASSERT_EQUALS(expected, tokenizeAndStringify(code));
43264326
}
43274327
}

0 commit comments

Comments
 (0)