Skip to content

Partial fix for #13747 assertion in Token::update_property_info() (no variable declaration in static_assert) #7462

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4709,6 +4709,11 @@ void Tokenizer::setVarIdPass1()
if (!isC() && Token::simpleMatch(tok2, "const new"))
continue;

if (tok->isKeyword() && Token::simpleMatch(tok, "static_assert (")) {
tok = tok->linkAt(1);
continue;
}

bool decl;
if (cpp && mSettings.standards.cpp >= Standards::CPP17 && Token::Match(tok, "[(;{}] const| auto &|&&| [")) {
// Structured bindings
Expand Down
7 changes: 7 additions & 0 deletions test/testvarid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class TestVarID : public TestFixture {
TEST_CASE(varid69);
TEST_CASE(varid70); // #12660 - function
TEST_CASE(varid71); // #12676 - wrong varid in uninstantiated templated constructor
TEST_CASE(varid72);
TEST_CASE(varid_for_1);
TEST_CASE(varid_for_2);
TEST_CASE(varid_for_3);
Expand Down Expand Up @@ -1394,6 +1395,12 @@ class TestVarID : public TestFixture {
ASSERT_EQUALS(expected, tokenize(code));
}

void varid72() {
const char code[] = "static_assert(true && false);\n";
const char expected[] = "1: static_assert ( true && false ) ;\n";
ASSERT_EQUALS(expected, tokenize(code));
}

void varid_for_1() {
const char code[] = "void foo(int a, int b) {\n"
" for (int a=1,b=2;;) {}\n"
Expand Down
Loading