From 101ddea1e6f9074910f06366cf7c883a39eab414 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Fri, 21 Jul 2023 17:33:18 +0200 Subject: [PATCH] Fix #11840 FP constStatement with template parameters on operator (#5258) --- lib/tokenize.cpp | 3 ++- test/testtokenize.cpp | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index b49aa46e4..302c20231 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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") diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index fc8558bc9..2e0972d07 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -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\n" + " void operator() (int);\n" + "};\n" + "void f() {\n" + " S s;\n" + " s.operator()(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() {