From 24dd4c9c26c81741df0acb8736d37a79935308d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 1 Jul 2018 22:31:45 +0200 Subject: [PATCH] Restore code in checkVariableScope. Fixes false negative --- lib/checkother.cpp | 2 +- test/testother.cpp | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 22314f627..2595a7d76 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1097,7 +1097,7 @@ void CheckOther::checkVariableScope() const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase(); for (const Variable* var : symbolDatabase->variableList()) { - if (!var || !var->isLocal() || (!var->isPointer() && !var->isReference() && var->valueType()->type <= ValueType::Type::RECORD)) + if (!var || !var->isLocal() || (!var->isPointer() && !var->isReference() && !var->typeStartToken()->isStandardType())) continue; if (var->isConst()) diff --git a/test/testother.cpp b/test/testother.cpp index 1e74974cb..ae081ddc4 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -83,6 +83,7 @@ private: TEST_CASE(varScope22); // Ticket #5684 TEST_CASE(varScope23); // Ticket #6154 TEST_CASE(varScope24); // pointer / reference + TEST_CASE(varScope25); // time_t TEST_CASE(oldStylePointerCast); TEST_CASE(invalidPointerCast); @@ -1159,6 +1160,16 @@ private: ASSERT_EQUALS("", errout.str()); } + void varScope25() { + check("void f() {\n" + " time_t currtime;\n" + " if (a) {\n" + " currtime = time(&dummy);\n" + " if (currtime > t) {}\n" + " }\n" + "}", "test.c"); + ASSERT_EQUALS("[test.c:2]: (style) The scope of the variable 'currtime' can be reduced.\n", errout.str()); + } void checkOldStylePointerCast(const char code[]) { // Clear the error buffer.. errout.str("");