diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 276154b36..ba6a17b0e 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -373,7 +373,7 @@ static const Token *getCastTypeStartToken(const Token *parent) // does the operation cause a loss of information? static bool isNonInvertibleOperation(const Token* tok) { - return tok->isComparisonOp() || Token::Match(tok, "%|/|&|%or%|<<|>>|%oror%|&&"); + return !Token::Match(tok, "+|-"); } static bool isComputableValue(const Token* parent, const ValueFlow::Value& value) diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 2578569e1..b6b3f4bed 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -876,6 +876,7 @@ private: ASSERT_EQUALS(0, valueOfTok("(UNKNOWN_TYPE*)0;","(").intvalue); ASSERT_EQUALS(100, valueOfTok("(int)100.0;", "(").intvalue); ASSERT_EQUALS(10, valueOfTok("x = static_cast(10);", "( 10 )").intvalue); + ASSERT_EQUALS(0, valueOfTok("x = sizeof (struct {int a;}) * 0;", "*").intvalue); // Don't calculate if there is UB ASSERT(tokenValues(";-1<<10;","<<").empty());