From 6947e112a82311ae16c7db4010f2fa5bc57dd045 Mon Sep 17 00:00:00 2001 From: Anton Lindqvist Date: Wed, 11 Dec 2024 20:32:07 +0100 Subject: [PATCH] Ignore knownConditionTrueFalse in static assertions _Static_assert (deprecated in C23) should be treated like static_assert. --- lib/checkother.cpp | 8 +++++++- test/testother.cpp | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 1b4cb0e1393..8acc294fdc3 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2574,6 +2574,12 @@ namespace { } } +static bool +isStaticAssert(const Token *tok) +{ + return Token::Match(tok, "_Static_assert|static_assert ("); +} + void CheckOther::checkDuplicateExpression() { { @@ -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; } } diff --git a/test/testother.cpp b/test/testother.cpp index 3eeb3089b79..b5a62935ec8 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -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"