Fixed #6614 (false positive: (style) The class 'A' does not have a constructor.)

This commit is contained in:
Robert Reif 2015-04-04 11:33:25 +02:00 committed by Daniel Marjamäki
parent 77e22da7fe
commit c02acea5bf
2 changed files with 60 additions and 36 deletions

View File

@ -1303,6 +1303,8 @@ bool SymbolDatabase::isFunction(const Token *tok, const Scope* outerScope, const
tok1 = tok1->tokAt(-1); tok1 = tok1->tokAt(-1);
} }
// done if constructor or destructor
if (!Token::Match(tok1, "{|}|;|public:|protected:|private:") && tok1) {
// skip over pointers and references // skip over pointers and references
while (Token::Match(tok1, "[*&]")) while (Token::Match(tok1, "[*&]"))
tok1 = tok1->tokAt(-1); tok1 = tok1->tokAt(-1);
@ -1341,6 +1343,7 @@ bool SymbolDatabase::isFunction(const Token *tok, const Scope* outerScope, const
// should be at a sequence point if this is a function // should be at a sequence point if this is a function
if (!Token::Match(tok1, ">|{|}|;|public:|protected:|private:") && tok1) if (!Token::Match(tok1, ">|{|}|;|public:|protected:|private:") && tok1)
return false; return false;
}
const Token* tok2 = tok->next()->link()->next(); const Token* tok2 = tok->next()->link()->next();
if (tok2 && if (tok2 &&

View File

@ -73,6 +73,7 @@ private:
TEST_CASE(noConstructor7); // ticket #4391 TEST_CASE(noConstructor7); // ticket #4391
TEST_CASE(noConstructor8); // ticket #4404 TEST_CASE(noConstructor8); // ticket #4404
TEST_CASE(noConstructor9); // ticket #4419 TEST_CASE(noConstructor9); // ticket #4419
TEST_CASE(noConstructor10); // ticket #6614
TEST_CASE(forwardDeclaration); // ticket #4290/#3190 TEST_CASE(forwardDeclaration); // ticket #4290/#3190
@ -509,6 +510,26 @@ private:
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
void noConstructor10() {
// ticket #6614
check("class A : public wxDialog\n"
"{\n"
"private:\n"
" DECLARE_EVENT_TABLE()\n"
"public:\n"
" A(wxWindow *parent,\n"
" wxWindowID id = 1,\n"
" const wxString &title = wxT(""),\n"
" const wxPoint& pos = wxDefaultPosition,\n"
" const wxSize& size = wxDefaultSize,\n"
" long style = wxDIALOG_NO_PARENT | wxMINIMIZE_BOX | wxMAXIMIZE_BOX | wxCLOSE_BOX);\n"
" virtual ~A();\n"
"private:\n"
" wxTimer *WxTimer1;\n"
"};\n");
ASSERT_EQUALS("", errout.str());
}
// ticket #4290 "False Positive: style (noConstructor): The class 'foo' does not have a constructor." // ticket #4290 "False Positive: style (noConstructor): The class 'foo' does not have a constructor."
// ticket #3190 "SymbolDatabase: Parse of sub class constructor fails" // ticket #3190 "SymbolDatabase: Parse of sub class constructor fails"
void forwardDeclaration() { void forwardDeclaration() {