Fix #10882 FP constStatement with negation and cast (#3951)

This commit is contained in:
chrchr-github 2022-03-28 21:52:08 +02:00 committed by GitHub
parent 7b97230dd2
commit d57d536f01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 1 deletions

View File

@ -566,7 +566,7 @@ static bool iscast(const Token *tok, bool cpp)
} }
return type || tok2->strAt(-1) == "*" || Token::simpleMatch(tok2, ") ~") || return type || tok2->strAt(-1) == "*" || Token::simpleMatch(tok2, ") ~") ||
(Token::Match(tok2, ") %any%") && (Token::Match(tok2, ") %any%") &&
!tok2->next()->isOp() && (!tok2->next()->isOp() || Token::Match(tok2->next(), "!|~|++|--")) &&
!Token::Match(tok2->next(), "[[]);,?:.]")); !Token::Match(tok2->next(), "[[]);,?:.]"));
} }

View File

@ -555,6 +555,13 @@ private:
" f(1, { static_cast<int*>(nullptr) });\n" " f(1, { static_cast<int*>(nullptr) });\n"
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
check("struct S { int i; };\n" // #10882
"enum E {};\n"
"void f(const S* s) {\n"
" E e = (E)!s->i;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
} }
void vardecl() { void vardecl() {

View File

@ -6298,6 +6298,8 @@ private:
ASSERT_EQUALS("fon!(restoring01:?,(", testAst("f((long) !on, restoring ? 0 : 1);")); ASSERT_EQUALS("fon!(restoring01:?,(", testAst("f((long) !on, restoring ? 0 : 1);"));
ASSERT_EQUALS("esi.!(=", testAst("E e = (E)!s->i;")); // #10882
// not cast // not cast
ASSERT_EQUALS("AB||", testAst("(A)||(B)")); ASSERT_EQUALS("AB||", testAst("(A)||(B)"));
ASSERT_EQUALS("abc[1&=", testAst("a = (b[c]) & 1;")); ASSERT_EQUALS("abc[1&=", testAst("a = (b[c]) & 1;"));