Reviewed handling of unknown types in C files in checkunusedvar
This commit is contained in:
parent
bc9e419615
commit
951da02f89
|
@ -608,7 +608,7 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
|
|||
type = Variables::pointerPointer;
|
||||
else if (i->isPointer())
|
||||
type = Variables::pointer;
|
||||
else if (i->typeEndToken()->isStandardType() || isRecordTypeWithoutSideEffects(*i) || Token::simpleMatch(i->nameToken()->tokAt(-3), "std :: string"))
|
||||
else if (_tokenizer->isC() || i->typeEndToken()->isStandardType() || isRecordTypeWithoutSideEffects(*i) || Token::simpleMatch(i->nameToken()->tokAt(-3), "std :: string"))
|
||||
type = Variables::standard;
|
||||
if (type == Variables::none || isPartOfClassStructUnion(i->typeStartToken()))
|
||||
continue;
|
||||
|
|
|
@ -366,7 +366,7 @@ private:
|
|||
ASSERT_EQUALS("[test.cpp:3]: (style) struct or union member 'AB::a' is never used\n", errout.str());
|
||||
}
|
||||
|
||||
void functionVariableUsage(const char code[]) {
|
||||
void functionVariableUsage(const char code[], const char filename[]="test.cpp") {
|
||||
// Clear the error buffer..
|
||||
errout.str("");
|
||||
|
||||
|
@ -376,7 +376,7 @@ private:
|
|||
// Tokenize..
|
||||
Tokenizer tokenizer(&settings, this);
|
||||
std::istringstream istr(code);
|
||||
tokenizer.tokenize(istr, "test.cpp");
|
||||
tokenizer.tokenize(istr, filename);
|
||||
|
||||
// Check for unused variables..
|
||||
CheckUnusedVar checkUnusedVar(&tokenizer, &settings, this);
|
||||
|
@ -484,6 +484,13 @@ private:
|
|||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
functionVariableUsage("undefined foo()\n"
|
||||
"{\n"
|
||||
" undefined i = 0;\n"
|
||||
"}\n",
|
||||
"test.c");
|
||||
ASSERT_EQUALS("[test.c:3]: (style) Variable 'i' is assigned a value that is never used\n", errout.str());
|
||||
|
||||
functionVariableUsage("void foo()\n"
|
||||
"{\n"
|
||||
" int i = undefined;\n"
|
||||
|
@ -593,6 +600,14 @@ private:
|
|||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
functionVariableUsage("undefined foo()\n"
|
||||
"{\n"
|
||||
" undefined i;\n"
|
||||
" return i;\n"
|
||||
"}\n",
|
||||
"test.c");
|
||||
ASSERT_EQUALS("[test.c:3]: (style) Variable 'i' is not assigned a value\n", errout.str());
|
||||
|
||||
functionVariableUsage("undefined *foo()\n"
|
||||
"{\n"
|
||||
" undefined * i;\n"
|
||||
|
@ -2357,6 +2372,15 @@ private:
|
|||
" ref[0] = 123;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
functionVariableUsage("void foo()\n"
|
||||
"{\n"
|
||||
" Foo foo;\n"
|
||||
" Foo &ref = foo;\n"
|
||||
" ref[0] = 123;\n"
|
||||
"}",
|
||||
"test.c");
|
||||
ASSERT_EQUALS("[test.c:3]: (style) Variable 'foo' is assigned a value that is never used\n", errout.str());
|
||||
}
|
||||
|
||||
void localvaralias10() { // ticket 2004
|
||||
|
@ -2367,6 +2391,15 @@ private:
|
|||
" *x = 0;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
functionVariableUsage("void foo(Foo &foo)\n"
|
||||
"{\n"
|
||||
" Foo &ref = foo;\n"
|
||||
" int *x = &ref.x;\n"
|
||||
" *x = 0;\n"
|
||||
"}",
|
||||
"test.c");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void localvarasm() {
|
||||
|
@ -2430,6 +2463,13 @@ private:
|
|||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
functionVariableUsage("int foo() {\n"
|
||||
" A a;\n"
|
||||
" return 0;\n"
|
||||
"}\n",
|
||||
"test.c");
|
||||
ASSERT_EQUALS("[test.c:2]: (style) Unused variable: a\n", errout.str());
|
||||
|
||||
functionVariableUsage("struct A { int i; };\n"
|
||||
"int foo() {\n"
|
||||
" A a;\n"
|
||||
|
|
Loading…
Reference in New Issue