Class Checking: No constructor

This commit is contained in:
Daniel Marjamäki 2008-02-18 16:28:37 +00:00
parent f06c65c071
commit 46d8fe0fad
2 changed files with 14 additions and 11 deletions

View File

@ -208,12 +208,18 @@ void CheckConstructors()
const char *classname = tok1->next->str;
// Are there a class constructor?
const char *pattern_constructor[] = {"clKalle","::","clKalle","(",NULL};
pattern_constructor[0] = classname;
pattern_constructor[2] = classname;
if (!findtoken(tokens,pattern_constructor))
const char *constructor_pattern[] = {"","clKalle","(",NULL};
constructor_pattern[1] = classname;
TOKEN *constructor_token = findtoken( tokens, constructor_pattern );
while ( constructor_token && constructor_token->str[0] == '~' )
constructor_token = findtoken( constructor_token->next, constructor_pattern );
if ( ! constructor_token )
{
// There's no class implementation, it must be somewhere else.
// There's no class constructor
std::ostringstream ostr;
ostr << FileLine(tok1);
ostr << " The class '" << classname << "' has no constructor";
ReportErr(ostr.str());
tok1 = findtoken( tok1->next, pattern_classname );
continue;
}
@ -221,10 +227,7 @@ void CheckConstructors()
// Check that all member variables are initialized..
struct VAR *varlist = ClassChecking_GetVarList(classname);
const char *constructor_pattern[] = {"","::","","(",NULL};
constructor_pattern[0] = classname;
constructor_pattern[2] = classname;
struct TOKEN *constructor_token = ClassChecking_VarList_Initialize(tokens, varlist, classname, classname);
constructor_token = ClassChecking_VarList_Initialize(tokens, varlist, classname, classname);
while ( constructor_token )
{
// Check if any variables are uninitialized

View File

@ -354,7 +354,7 @@ static void buffer_overrun()
static void constructors()
{
// Test1: No constructor => Uninitialized variable (TODO)
// Test1: No constructor
// Test2: embedded constructor, uninitialized variable (TODO)
// Test3: Uninitialized variable
// Test4: multiple constructors, uninitialized variable
@ -364,7 +364,7 @@ static void constructors()
"public:\n"
" int i;\n"
"};\n";
check( CheckConstructors, __LINE__, test1, "" );
check( CheckConstructors, __LINE__, test1, "[test.cpp:1] The class 'clKalle' has no constructor\n" );