Fixed #3532 (false positive : missing constructor)

This commit is contained in:
Daniel Marjamäki 2012-03-31 11:30:26 +02:00
parent 1309825bf1
commit 68e6511c87
2 changed files with 15 additions and 5 deletions

View File

@ -237,6 +237,7 @@ void TemplateSimplifier::removeTemplates(Token *tok)
continue; continue;
int indentlevel = 0; int indentlevel = 0;
unsigned int countgt = 0; // Counter for ">"
for (const Token *tok2 = tok->next(); tok2; tok2 = tok2->next()) { for (const Token *tok2 = tok->next(); tok2; tok2 = tok2->next()) {
if (tok2->str() == "(") { if (tok2->str() == "(") {
@ -260,8 +261,14 @@ void TemplateSimplifier::removeTemplates(Token *tok)
tok->deleteThis(); tok->deleteThis();
break; break;
} }
// Count ">"
if (tok2->str() == ">")
countgt++;
// don't remove constructor // don't remove constructor
if (tok2->str() == "explicit") { if (tok2->str() == "explicit" ||
(countgt == 1 && Token::Match(tok2->previous(), "> %type% (") && Token::simpleMatch(tok2->next()->link(), ") {"))) {
Token::eraseTokens(tok, tok2); Token::eraseTokens(tok, tok2);
tok->deleteThis(); tok->deleteThis();
goback = true; goback = true;
@ -282,10 +289,7 @@ void TemplateSimplifier::removeTemplates(Token *tok)
else if (indentlevel >= 2 && tok2->str() == ">") else if (indentlevel >= 2 && tok2->str() == ">")
--indentlevel; --indentlevel;
else if (indentlevel >= 3 && tok2->str() == ">>") else if (Token::Match(tok2, "> class|struct %var% [,)]")) {
indentlevel -= 2;
else if (Token::Match(tok2, ">|>> class|struct %var% [,)]")) {
tok2 = tok2->next(); tok2 = tok2->next();
Token::eraseTokens(tok, tok2); Token::eraseTokens(tok, tok2);
tok->deleteThis(); tok->deleteThis();

View File

@ -2320,6 +2320,12 @@ private:
" template<class T> explicit Fred(T t) { }\n" " template<class T> explicit Fred(T t) { }\n"
"}"; "}";
ASSERT_EQUALS("class Fred { explicit Fred ( T t ) { } }", tok(code)); ASSERT_EQUALS("class Fred { explicit Fred ( T t ) { } }", tok(code));
// #3532
const char code2[] = "class Fred {\n"
" template<class T> Fred(T t) { }\n"
"}";
ASSERT_EQUALS("class Fred { Fred ( T t ) { } }", tok(code2));
} }
void namespaces() { void namespaces() {