File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ())
Original file line number Diff line number Diff 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 (" " );
You can’t perform that action at this time.
0 commit comments