From a73e989d1ab2b821c654b809fd8610d8b979de53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 1 Jan 2019 11:34:44 +0100 Subject: [PATCH] isConstVarExpression: Fix FPs when there is C++ cast --- lib/astutils.cpp | 3 +++ test/testother.cpp | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 92c9b2f29..1d4b2d6a9 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -1050,6 +1050,9 @@ bool isConstVarExpression(const Token *tok) std::vector args = getArguments(tok); return std::all_of(args.begin(), args.end(), &isConstVarExpression); } + if (Token::simpleMatch(tok->previous(), "> (") && tok->astOperand2() && tok->astOperand1()->str().find("_cast") != std::string::npos) { + return isConstVarExpression(tok->astOperand2()); + } if (Token::Match(tok, "( %type%")) return isConstVarExpression(tok->astOperand1()); if (Token::Match(tok, "%cop%")) { diff --git a/test/testother.cpp b/test/testother.cpp index 92cb5340c..22d0542ed 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -7599,6 +7599,12 @@ private: "}\n"); ASSERT_EQUALS("", errout.str()); + check("void g(Foo *);\n" + "void f() {\n" + " g(reinterpret_cast(0));\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + check("void g(int);\n" "void f(int x) {\n" " x = 0;\n"