Fixed #5055 (False negatives when using -I (external source code))

This commit is contained in:
Daniel Marjamäki 2013-09-29 18:59:27 +02:00
parent 00987eb120
commit 1c513f330a
2 changed files with 30 additions and 0 deletions

View File

@ -76,6 +76,27 @@ void TemplateSimplifier::cleanupAfterSimplify(Token *tokens)
if (tok->str() == "(") if (tok->str() == "(")
tok = tok->link(); tok = tok->link();
else if (Token::Match(tok, "template < > %var%")) {
const Token *end = tok;
while (end) {
if (end->str() == ";")
break;
if (end->str() == "{") {
end = end->link()->next();
break;
}
if (!Token::Match(end, "%var%|::|<|>|>>|,")) {
end = NULL;
break;
}
end = end->next();
}
if (end) {
Token::eraseTokens(tok,end);
tok->deleteThis();
}
}
else if (Token::Match(tok, "%type% <") && else if (Token::Match(tok, "%type% <") &&
(!tok->previous() || tok->previous()->str() == ";")) { (!tok->previous() || tok->previous()->str() == ";")) {
const Token *tok2 = tok->tokAt(2); const Token *tok2 = tok->tokAt(2);

View File

@ -132,6 +132,7 @@ private:
TEST_CASE(template37); // #4544 - A<class B> a; TEST_CASE(template37); // #4544 - A<class B> a;
TEST_CASE(template38); // #4832 - crash on C++11 right angle brackets TEST_CASE(template38); // #4832 - crash on C++11 right angle brackets
TEST_CASE(template39); // #4742 - freeze TEST_CASE(template39); // #4742 - freeze
TEST_CASE(template40); // #5055 - template specialization outside struct
TEST_CASE(template_unhandled); TEST_CASE(template_unhandled);
TEST_CASE(template_default_parameter); TEST_CASE(template_default_parameter);
TEST_CASE(template_default_type); TEST_CASE(template_default_type);
@ -2324,6 +2325,14 @@ private:
tok(code); tok(code);
} }
void template40() { // #5055 - false negatives when there is template specialization outside struct
const char code[] = "struct A {"
" template<typename T> struct X { T t; };"
"};"
"template<> struct A::X<int> { int *t; };";
ASSERT_EQUALS("struct A { template < typename T > struct X { T t ; } ; } ;", tok(code));
}
void template_default_parameter() { void template_default_parameter() {
{ {
const char code[] = "template <class T, int n=3>\n" const char code[] = "template <class T, int n=3>\n"