Skip to content

Commit

Permalink
Fix #11840 FP constStatement with template parameters on operator
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Jul 21, 2023
1 parent d2546d5 commit 20c9e9e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5249,7 +5249,7 @@ 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::Match(token->tokAt(-1), "]|)") && (!Token::Match(token->linkAt(-1)->previous(), "%name%|)") || token->linkAt(-1)->previous()->isKeyword())))) ||
Token::Match(token->next(), ">|>>"))) {
type.push(token);
if (token->previous()->str() == "template")
Expand Down
19 changes: 19 additions & 0 deletions test/testtokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3531,6 +3531,25 @@ class TestTokenizer : public TestFixture {
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() {
Expand Down

0 comments on commit 20c9e9e

Please sign in to comment.