Skip to content

Commit

Permalink
Fix #13578 Crash in setParentExprId() (#7255)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Jan 25, 2025
1 parent caa3b75 commit 0eb54ba
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1609,7 +1609,7 @@ namespace {
typeEndToken = tok->astParent()->link();
}
std::string type;
for (const Token* t = typeStartToken; t != typeEndToken; t = t->next()) {
for (const Token* t = typeStartToken; precedes(t, typeEndToken); t = t->next()) {
type += " " + t->str();
}
key.parentOp += type;
Expand Down
14 changes: 14 additions & 0 deletions test/testvarid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ class TestVarID : public TestFixture {
TEST_CASE(exprid11);
TEST_CASE(exprid12);
TEST_CASE(exprid13);
TEST_CASE(exprid14);

TEST_CASE(structuredBindings);
}
Expand Down Expand Up @@ -4359,6 +4360,19 @@ class TestVarID : public TestFixture {
ASSERT_EQUALS(exp, tokenizeExpr(code));
}

void exprid14()
{
const Settings s = settingsBuilder(settings).library("std.cfg").build();

const char code[] = "int f(double a, double b, double c) {\n" // #13578
" return static_cast<int>(std::ceil((std::min)(a, (std::min)(b, c))));\n"
"}\n";
const char* exp = "1: int f ( double a@1 , double b@2 , double c@3 ) {\n"
"2: return static_cast < int > ( std :: ceil ( ( std :: min ) ( a@1 , ( std :: min ) ( b@2 , c@3 ) ) ) ) ;\n"
"3: }\n";
ASSERT_EQUALS(exp, tokenize(code, dinit(TokenizeOptions, $.s = &s))); // don't crash
}

void structuredBindings() {
const char code[] = "int foo() { auto [x,y] = xy(); return x+y; }";
ASSERT_EQUALS("1: int foo ( ) { auto [ x@1 , y@2 ] = xy ( ) ; return x@1 + y@2 ; }\n",
Expand Down

0 comments on commit 0eb54ba

Please sign in to comment.