Skip to content

Commit

Permalink
Ignore knownConditionTrueFalse in static assertions
Browse files Browse the repository at this point in the history
_Static_assert (deprecated in C23) should be treated like static_assert.
  • Loading branch information
mptre committed Dec 15, 2024
1 parent 02063b6 commit 6947e11
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/checkother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2574,6 +2574,12 @@ namespace {
}
}

static bool
isStaticAssert(const Token *tok)
{
return Token::Match(tok, "_Static_assert|static_assert (");
}

void CheckOther::checkDuplicateExpression()
{
{
Expand Down Expand Up @@ -2700,7 +2706,7 @@ void CheckOther::checkDuplicateExpression()
while (parent && parent->astParent()) {
parent = parent->astParent();
}
if (parent && parent->previous() && parent->strAt(-1) == "static_assert") {
if (parent && isStaticAssert(parent->previous())) {
continue;
}
}
Expand Down
6 changes: 6 additions & 0 deletions test/testother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6917,6 +6917,12 @@ class TestOther : public TestFixture {
"}");
ASSERT_EQUALS("", errout_str());

check("void f() {\n"
" enum { Four = 4 };\n"
" _Static_assert(Four == 4, \"\");\n"
"}");
ASSERT_EQUALS("", errout_str());

check("void f() {\n"
" enum { Four = 4 };\n"
" static_assert(4 == Four, \"\");\n"
Expand Down

0 comments on commit 6947e11

Please sign in to comment.