ClassChecking: Only enable the 'no constructor' warning if '--style' is given

This commit is contained in:
Daniel Marjamäki 2008-02-18 17:04:14 +00:00
parent 46d8fe0fad
commit edc4177df3
2 changed files with 14 additions and 8 deletions

View File

@ -8,6 +8,8 @@
#include <sstream> #include <sstream>
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
extern bool CheckCodingStyle;
struct VAR struct VAR
{ {
const char *name; const char *name;
@ -216,10 +218,14 @@ void CheckConstructors()
if ( ! constructor_token ) if ( ! constructor_token )
{ {
// There's no class constructor // There's no class constructor
std::ostringstream ostr; if ( CheckCodingStyle )
ostr << FileLine(tok1); {
ostr << " The class '" << classname << "' has no constructor"; std::ostringstream ostr;
ReportErr(ostr.str()); ostr << FileLine(tok1);
ostr << " The class '" << classname << "' has no constructor";
ReportErr(ostr.str());
}
tok1 = findtoken( tok1->next, pattern_classname ); tok1 = findtoken( tok1->next, pattern_classname );
continue; continue;
} }

View File

@ -16,6 +16,7 @@
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
bool ShowAll = true; bool ShowAll = true;
bool CheckCodingStyle = true;
bool Debug = false; bool Debug = false;
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
static unsigned int FailCount, SuccessCount; static unsigned int FailCount, SuccessCount;
@ -454,16 +455,16 @@ static void memleak_in_function()
const char test3[] = "void f()\n" const char test3[] = "void f()\n"
"{\n" "{\n"
" Kalle *kalle;\n" " Fred *fred;\n"
" if (somecondition)\n" " if (somecondition)\n"
" {\n" " {\n"
" kalle = new Kalle;\n" " fred = new Fred;\n"
" }\n" " }\n"
" else\n" " else\n"
" {\n" " {\n"
" return;\n" " return;\n"
" }\n" " }\n"
" delete kalle;\n" " delete fred;\n"
"}\n"; "}\n";
check( CheckMemoryLeak, __LINE__, test3, "" ); check( CheckMemoryLeak, __LINE__, test3, "" );
@ -549,7 +550,6 @@ static void memleak_in_function()
" free(a);\n" " free(a);\n"
"}\n"; "}\n";
check( CheckMemoryLeak, __LINE__, test9, "[test.cpp:4]: Mismatching allocation and deallocation 'a'\n" ); check( CheckMemoryLeak, __LINE__, test9, "[test.cpp:4]: Mismatching allocation and deallocation 'a'\n" );
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------