Fix #11840 FP constStatement with template parameters on operator (#5258)

This commit is contained in:
chrchr-github 2023-07-21 17:33:18 +02:00 committed by GitHub
parent a6b0129725
commit 101ddea1e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 1 deletions

View File

@ -5250,7 +5250,8 @@ void Tokenizer::createLinks2()
} else if (token->str() == "<" &&
((token->previous() && (token->previous()->isTemplate() ||
(token->previous()->isName() && !token->previous()->varId()) ||
(token->strAt(-1) == "]" && (!Token::Match(token->linkAt(-1)->previous(), "%name%|)") || token->linkAt(-1)->previous()->isKeyword())))) ||
(token->strAt(-1) == "]" && (!Token::Match(token->linkAt(-1)->previous(), "%name%|)") || token->linkAt(-1)->previous()->isKeyword())) ||
(token->strAt(-1) == ")" && token->linkAt(-1)->strAt(-1) == "operator"))) ||
Token::Match(token->next(), ">|>>"))) {
type.push(token);
if (token->previous()->str() == "template")

View File

@ -3531,6 +3531,25 @@ private:
ASSERT_EQUALS(true, tok1->link() == tok2);
ASSERT_EQUALS(true, tok2->link() == tok1);
}
{
const char code[] = "struct S {\n" // #11840
" template<typename T, typename U>\n"
" void operator() (int);\n"
"};\n"
"void f() {\n"
" S s;\n"
" s.operator()<int, int>(1);\n"
"}\n";
errout.str("");
Tokenizer tokenizer(&settings0, this);
std::istringstream istr(code);
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
const Token* tok1 = Token::findsimplematch(tokenizer.tokens(), "< int");
const Token* tok2 = Token::findsimplematch(tok1, "> (");
ASSERT_EQUALS(true, tok1->link() == tok2);
ASSERT_EQUALS(true, tok2->link() == tok1);
}
}
void simplifyString() {