Skip to content

Commit c24bf0e

Browse files
Fix #14615 internalError "Cannot find end of expression" with brace init (#8376)
1 parent b0d3ec4 commit c24bf0e

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

lib/tokenize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5544,7 +5544,7 @@ void Tokenizer::createLinks2()
55445544

55455545
while (!type.empty() && type.top()->str() == "<") {
55465546
const Token* end = type.top()->findClosingBracket();
5547-
if (Token::Match(end, "> %comp%|;|.|=|{|(|)|::"))
5547+
if (Token::Match(end, "> %comp%|;|.|=|{|}|(|)|::"))
55485548
break;
55495549
// Variable declaration
55505550
if (Token::Match(end, "> %var% ;") && (type.top()->tokAt(-2) == nullptr || Token::Match(type.top()->tokAt(-2), ";|}|{")))

test/testtokenize.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3820,7 +3820,7 @@ class TestTokenizer : public TestFixture {
38203820

38213821
{
38223822
const char code[] = "template <typename Fn, typename... Args>\n" // #14612
3823-
"void f(Fn && fn, Args&&... args) {\n"
3823+
"void f(Fn&& fn, Args&&... args) {\n"
38243824
" static_assert(std::is_invocable_v<Fn&&, Args&&...>);\n"
38253825
"}\n";
38263826
SimpleTokenizer tokenizer(settingsDefault, *this);
@@ -3830,6 +3830,19 @@ class TestTokenizer : public TestFixture {
38303830
ASSERT_EQUALS(true, tok1->link() == tok2);
38313831
ASSERT_EQUALS(true, tok2->link() == tok1);
38323832
}
3833+
3834+
{
3835+
const char code[] = "template <typename Fn, typename... Args>\n" // #14615
3836+
"void f(Fn&& fn, Args&&... args) {\n"
3837+
" constexpr bool b{ std::is_invocable_v<Fn&&, Args&&...> };\n"
3838+
"}\n";
3839+
SimpleTokenizer tokenizer(settingsDefault, *this);
3840+
ASSERT(tokenizer.tokenize(code));
3841+
const Token* tok1 = Token::findsimplematch(tokenizer.tokens(), "< Fn");
3842+
const Token* tok2 = Token::findsimplematch(tok1, "> }");
3843+
ASSERT_EQUALS(true, tok1->link() == tok2);
3844+
ASSERT_EQUALS(true, tok2->link() == tok1);
3845+
}
38333846
}
38343847

38353848
void simplifyString() {

0 commit comments

Comments
 (0)