Skip to content

Commit

Permalink
Partial fix for #12475 internalError: Cannot find end of expression (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Mar 18, 2024
1 parent 4d9e2a8 commit 00c756a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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), ";|}|{")))
Expand All @@ -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;
}
Expand Down
30 changes: 30 additions & 0 deletions test/testtokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3531,6 +3531,36 @@ class TestTokenizer : public TestFixture {
ASSERT_EQUALS(true, tok1->link() == tok2);
ASSERT_EQUALS(true, tok2->link() == tok1);
}

{
const char code[] = "template<typename T>\n"
"auto f() {\n"
" return std::integral_constant<\n"
" bool,\n"
" std::is_same<typename T::size_type, std::size_t>::value && std::is_same<typename T::size_type, std::size_t>::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<int, double> ? 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() {
Expand Down

0 comments on commit 00c756a

Please sign in to comment.