Fix issue 8890: AST broken calling member function from templated base class (#1836)

* Fix issue 8890: AST broken calling member function from templated base class

* Format

* Check for double bracket

* Add test to createLinks2

* Remove extra test

* Reduce test case for links
This commit is contained in:
Paul Fultz II 2019-05-19 03:05:34 -05:00 committed by Daniel Marjamäki
parent 03b4447350
commit 8cbd9b03aa
2 changed files with 28 additions and 1 deletions

View File

@ -3847,7 +3847,9 @@ void Tokenizer::createLinks2()
while (!type.empty() && type.top()->str() == "<") while (!type.empty() && type.top()->str() == "<")
type.pop(); type.pop();
} else if (token->str() == "<" && token->previous() && token->previous()->isName() && !token->previous()->varId()) { } else if (token->str() == "<" &&
((token->previous() && token->previous()->isName() && !token->previous()->varId()) ||
Token::Match(token->next(), ">|>>"))) {
type.push(token); type.push(token);
if (!templateToken && (token->previous()->str() == "template")) if (!templateToken && (token->previous()->str() == "template"))
templateToken = token; templateToken = token;

View File

@ -455,6 +455,7 @@ private:
// The TestGarbage ensures that there are true positives // The TestGarbage ensures that there are true positives
TEST_CASE(findGarbageCode); TEST_CASE(findGarbageCode);
TEST_CASE(checkEnableIf); TEST_CASE(checkEnableIf);
TEST_CASE(checkTemplates);
// #9052 // #9052
TEST_CASE(noCrash1); TEST_CASE(noCrash1);
@ -4795,6 +4796,18 @@ private:
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
ASSERT(nullptr != Token::findsimplematch(tokenizer.tokens(), "<")->link()); ASSERT(nullptr != Token::findsimplematch(tokenizer.tokens(), "<")->link());
} }
{
// #8890
const char code[] = "void f() {\n"
" a<> b;\n"
" b.a<>::c();\n"
"}\n";
Tokenizer tokenizer(&settings0, this);
std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp");
ASSERT(nullptr != Token::findsimplematch(tokenizer.tokens(), "> ::")->link());
}
} }
void simplifyString() { void simplifyString() {
@ -7583,6 +7596,18 @@ private:
} }
void checkTemplates() {
ASSERT_NO_THROW(tokenizeAndStringify(
"template <typename = void> struct a {\n"
" void c();\n"
"};\n"
"void f() {\n"
" a<> b;\n"
" b.a<>::c();\n"
"}\n"))
}
void noCrash1() { void noCrash1() {
ASSERT_NO_THROW(tokenizeAndStringify( ASSERT_NO_THROW(tokenizeAndStringify(
"struct A {\n" "struct A {\n"