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

View File

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