Skip to content

Commit 24dd4c9

Browse files
committed
Restore code in checkVariableScope. Fixes false negative
1 parent bb73a74 commit 24dd4c9

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

lib/checkother.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1097,7 +1097,7 @@ void CheckOther::checkVariableScope()
10971097
const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase();
10981098

10991099
for (const Variable* var : symbolDatabase->variableList()) {
1100-
if (!var || !var->isLocal() || (!var->isPointer() && !var->isReference() && var->valueType()->type <= ValueType::Type::RECORD))
1100+
if (!var || !var->isLocal() || (!var->isPointer() && !var->isReference() && !var->typeStartToken()->isStandardType()))
11011101
continue;
11021102

11031103
if (var->isConst())

test/testother.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ class TestOther : public TestFixture {
8383
TEST_CASE(varScope22); // Ticket #5684
8484
TEST_CASE(varScope23); // Ticket #6154
8585
TEST_CASE(varScope24); // pointer / reference
86+
TEST_CASE(varScope25); // time_t
8687

8788
TEST_CASE(oldStylePointerCast);
8889
TEST_CASE(invalidPointerCast);
@@ -1159,6 +1160,16 @@ class TestOther : public TestFixture {
11591160
ASSERT_EQUALS("", errout.str());
11601161
}
11611162

1163+
void varScope25() {
1164+
check("void f() {\n"
1165+
" time_t currtime;\n"
1166+
" if (a) {\n"
1167+
" currtime = time(&dummy);\n"
1168+
" if (currtime > t) {}\n"
1169+
" }\n"
1170+
"}", "test.c");
1171+
ASSERT_EQUALS("[test.c:2]: (style) The scope of the variable 'currtime' can be reduced.\n", errout.str());
1172+
}
11621173
void checkOldStylePointerCast(const char code[]) {
11631174
// Clear the error buffer..
11641175
errout.str("");

0 commit comments

Comments
 (0)