From 00c756a77ed8d54414bacd0f81815698045aa0d3 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Mon, 18 Mar 2024 10:53:52 +0100 Subject: [PATCH] Partial fix for #12475 internalError: Cannot find end of expression (#6127) --- lib/tokenize.cpp | 4 ++-- test/testtokenize.cpp | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index a2dba01c5ea..b232e7bf35d 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -5355,7 +5355,7 @@ void Tokenizer::createLinks2() while (!type.empty() && type.top()->str() == "<") { const Token* end = type.top()->findClosingBracket(); - if (Token::Match(end, "> %comp%|;|.|=|{|::")) + if (Token::Match(end, "> %comp%|;|.|=|{|(|::")) break; // Variable declaration if (Token::Match(end, "> %var% ;") && (type.top()->tokAt(-2) == nullptr || Token::Match(type.top()->tokAt(-2), ";|}|{"))) @@ -5381,7 +5381,7 @@ void Tokenizer::createLinks2() if (!top2 || top2->str() != "<") { if (token->str() == ">>") continue; - if (!Token::Match(token->next(), "%name%|%cop%|%assign%|::|,|(|)|{|}|;|[|]|:|.|=|...") && + if (!Token::Match(token->next(), "%name%|%cop%|%assign%|::|,|(|)|{|}|;|[|]|:|.|=|?|...") && !Token::Match(token->next(), "&& %name% =")) continue; } diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 2d4f514f99d..73e50c4bc33 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -3531,6 +3531,36 @@ class TestTokenizer : public TestFixture { ASSERT_EQUALS(true, tok1->link() == tok2); ASSERT_EQUALS(true, tok2->link() == tok1); } + + { + const char code[] = "template\n" + "auto f() {\n" + " return std::integral_constant<\n" + " bool,\n" + " std::is_same::value && std::is_same::value\n" + " >();\n" + "}\n"; + Tokenizer tokenizer(settings0, this); + std::istringstream istr(code); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); + const Token* tok1 = Token::findsimplematch(tokenizer.tokens(), "< bool"); + const Token* tok2 = Token::findsimplematch(tok1, "> ("); + ASSERT_EQUALS(true, tok1->link() == tok2); + ASSERT_EQUALS(true, tok2->link() == tok1); + } + + { + const char code[] = "double f() {\n" + " return std::is_same_v ? 1e-7 : 1e-3;\n" + "}\n"; + 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() {