Fix FP unknownMacro (#5249)

This commit is contained in:
chrchr-github 2023-07-18 12:16:54 +02:00 committed by GitHub
parent c2ed362c11
commit 2878c68ec0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 0 deletions

View File

@ -8059,6 +8059,8 @@ void Tokenizer::reportUnknownMacros() const
// Report unknown macros before } "{ .. if (x) MACRO }"
for (const Token *tok = tokens(); tok; tok = tok->next()) {
if (Token::Match(tok, ")|; %name% } !!)")) {
if (tok->link() && !Token::simpleMatch(tok->link()->tokAt(-1), "if"))
continue;
const Token* prev = tok->linkAt(2);
while (Token::simpleMatch(prev, "{"))
prev = prev->previous();

View File

@ -6880,6 +6880,11 @@ private:
ASSERT_NO_THROW(tokenizeAndStringify("void f(void* q) {\n"
" g(&(S) { .p = (int*)q });\n"
"}\n", /*expand*/ true, cppcheck::Platform::Type::Native, "test.c"));
ASSERT_NO_THROW(tokenizeAndStringify("typedef struct { int i; } S;\n"
"void f(float a) {\n"
"S s = (S){ .i = (int)a };\n"
"}\n", /*expand*/ true, cppcheck::Platform::Type::Native, "test.c"));
}
void findGarbageCode() { // Test Tokenizer::findGarbageCode()