Misused scope objects: Don't use this check if the checked file is a pure C file. Ticket: #2352

This commit is contained in:
Daniel Marjamäki 2010-12-25 08:43:52 +01:00
parent 65041cf0ff
commit 81c5576eb4
2 changed files with 30 additions and 2 deletions

View File

@ -2517,6 +2517,14 @@ bool CheckOther::isIdentifierObjectType(const Token * const tok)
void CheckOther::checkMisusedScopedObject()
{
// Skip this check for .c files
{
const std::string fname = _tokenizer->getFiles()->at(0);
const std::string ext = fname.substr(fname.rfind("."));
if (ext == ".c" || ext == ".C")
return;
}
SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
std::list<SymbolDatabase::SpaceInfo *>::iterator i;

View File

@ -87,6 +87,7 @@ private:
TEST_CASE(testMisusedScopeObjectDoesNotPickFunctor);
TEST_CASE(testMisusedScopeObjectDoesNotPickLocalClassConstructors);
TEST_CASE(testMisusedScopeObjectDoesNotPickUsedObject);
TEST_CASE(testMisusedScopeObjectDoesNotPickPureC);
TEST_CASE(trac2071);
TEST_CASE(trac2084);
@ -94,7 +95,7 @@ private:
TEST_CASE(incorrectLogicOperator);
}
void check(const char code[])
void check(const char code[], const char *filename = NULL)
{
// Clear the error buffer..
errout.str("");
@ -105,7 +106,7 @@ private:
// Tokenize..
Tokenizer tokenizer(&settings, this);
std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp");
tokenizer.tokenize(istr, filename ? filename : "test.cpp");
// Check..
CheckOther checkOther(&tokenizer, &settings, this);
@ -1303,6 +1304,25 @@ private:
ASSERT_EQUALS("", errout.str());
}
void testMisusedScopeObjectDoesNotPickPureC()
{
// Ticket #2352
const char code[] = "struct cb_watch_bool {\n"
" int a;\n"
"};\n"
"\n"
"void f()\n"
"{\n"
" cb_watch_bool();\n"
"}\n";
check(code, "test.cpp");
ASSERT_EQUALS("[test.cpp:7]: (error) instance of \"cb_watch_bool\" object destroyed immediately\n", errout.str());
check(code, "test.c");
ASSERT_EQUALS("", errout.str());
}
void trac2084()
{
check("#include <signal.h>\n"