From 12fe6523217b83832cff7fd5262cf83364f92c49 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 7 Jun 2023 20:45:27 +0200 Subject: [PATCH] Fix #11063 FP unreadVariable with extra parentheses and scope operator (#5122) --- lib/token.cpp | 2 +- test/testunusedvar.cpp | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/token.cpp b/lib/token.cpp index 40f90ae29..2e07967e7 100644 --- a/lib/token.cpp +++ b/lib/token.cpp @@ -1459,7 +1459,7 @@ std::pair Token::findExpressionStartEndTokens() co } } if (Token::Match(end,"(|[|{") && - !(Token::Match(end, "( %type%") && !end->astOperand2())) { + !(Token::Match(end, "( ::| %type%") && !end->astOperand2())) { end = end->link(); break; } diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index 318865145..a1c580262 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -141,6 +141,7 @@ private: TEST_CASE(localvar66); // #11143 TEST_CASE(localvar67); // #9946 TEST_CASE(localvar68); + TEST_CASE(localvar69); TEST_CASE(localvarloops); // loops TEST_CASE(localvaralias1); TEST_CASE(localvaralias2); // ticket #1637 @@ -3774,6 +3775,16 @@ private: ASSERT_EQUALS("", errout.str()); } + void localvar69() { + functionVariableUsage("int g();\n" // #11063 + "int h(int);\n" + "int f() {\n" + " int i = g();\n" + " return (::h)(i);\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + } + void localvarloops() { // loops functionVariableUsage("void fun(int c) {\n"