From 49117f5aebf16085058bc55a68bc438e12701e9f Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 13 Jul 2022 21:08:43 +0200 Subject: [PATCH] Fix #7375 static_assert shouldn't be reported by --check-library (#4276) * No need to check smart pointers, since they take template arguments * Fix #7375 static_assert shouldn't be reported by --check-library --- lib/checkfunctions.cpp | 7 ++----- test/testfunctions.cpp | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/checkfunctions.cpp b/lib/checkfunctions.cpp index 75be215ed..a668aef10 100644 --- a/lib/checkfunctions.cpp +++ b/lib/checkfunctions.cpp @@ -608,10 +608,10 @@ void CheckFunctions::checkLibraryMatchFunctions() else if (insideNew) continue; - if (!Token::Match(tok, "%name% (") || Token::Match(tok, "asm|sizeof|catch")) + if (tok->isKeyword() || !Token::Match(tok, "%name% (")) continue; - if (tok->varId() != 0 || tok->type() || tok->isStandardType() || tok->isControlFlowKeyword()) + if (tok->varId() != 0 || tok->type() || tok->isStandardType()) continue; if (tok->linkAt(1)->strAt(1) == "(") @@ -630,9 +630,6 @@ void CheckFunctions::checkLibraryMatchFunctions() if (mSettings->library.functions.find(functionName) != mSettings->library.functions.end()) continue; - if (mSettings->library.smartPointers.find(functionName) != mSettings->library.smartPointers.end()) - continue; - const Token* start = tok; while (Token::Match(start->tokAt(-2), "%name% ::")) start = start->tokAt(-2); diff --git a/test/testfunctions.cpp b/test/testfunctions.cpp index 6758ddff7..0e7dd65a8 100644 --- a/test/testfunctions.cpp +++ b/test/testfunctions.cpp @@ -1813,6 +1813,20 @@ private: "}"); TODO_ASSERT_EQUALS("", "[test.cpp:6]: (information) --check-library: There is no matching configuration for function cb()\n", errout.str()); + // #7375 + check("void f() {\n" + " struct S { int i; char c; };\n" + " size_t s = sizeof(S);\n" + " static_assert(s == 9);\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + + check("void f(char) {}\n" + "void g() {\n" + " f(int8_t(1));\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + settings.severity = severity_old; settings.checkLibrary = false; }