diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index d2bd9d83e..8242e6240 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -566,7 +566,7 @@ static bool iscast(const Token *tok, bool cpp) } return type || tok2->strAt(-1) == "*" || Token::simpleMatch(tok2, ") ~") || (Token::Match(tok2, ") %any%") && - !tok2->next()->isOp() && + (!tok2->next()->isOp() || Token::Match(tok2->next(), "!|~|++|--")) && !Token::Match(tok2->next(), "[[]);,?:.]")); } diff --git a/test/testincompletestatement.cpp b/test/testincompletestatement.cpp index 0c249ac9e..768d7fe99 100644 --- a/test/testincompletestatement.cpp +++ b/test/testincompletestatement.cpp @@ -555,6 +555,13 @@ private: " f(1, { static_cast(nullptr) });\n" "}\n"); 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() { diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 1d9651cc3..80d4b32a3 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -6298,6 +6298,8 @@ private: ASSERT_EQUALS("fon!(restoring01:?,(", testAst("f((long) !on, restoring ? 0 : 1);")); + ASSERT_EQUALS("esi.!(=", testAst("E e = (E)!s->i;")); // #10882 + // not cast ASSERT_EQUALS("AB||", testAst("(A)||(B)")); ASSERT_EQUALS("abc[1&=", testAst("a = (b[c]) & 1;"));