Symbol database: match copy-constructor better. ticket: #2484

This commit is contained in:
Robert Reif 2011-01-22 17:43:36 +01:00 committed by Daniel Marjamäki
parent 1e25d74ba4
commit 8abae6f1e5
2 changed files with 42 additions and 2 deletions

View File

@ -155,6 +155,10 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
Token::Match(function.tokenDef, "%var% ( const %var% & %var% )")) &&
function.tokenDef->strAt(3) == scope->className)
function.type = Function::eCopyConstructor;
else if ((Token::Match(function.tokenDef, "%var% ( %var% & )") ||
Token::Match(function.tokenDef, "%var% ( %var% & %var% )")) &&
function.tokenDef->strAt(2) == scope->className)
function.type = Function::eCopyConstructor;
else
function.type = Function::eConstructor;

View File

@ -76,7 +76,8 @@ private:
TEST_CASE(initvar_private_constructor); // BUG 2354171 - private constructor
TEST_CASE(initvar_copy_constructor); // ticket #1611
TEST_CASE(initvar_nested_constructor); // ticket #1375
TEST_CASE(initvar_nocopy); // ticket #2474
TEST_CASE(initvar_nocopy1); // ticket #2474
TEST_CASE(initvar_nocopy2); // ticket #2484
TEST_CASE(initvar_destructor); // No variables need to be initialized in a destructor
@ -906,7 +907,7 @@ private:
"[test.cpp:24]: (warning) Member variable 'D::d' is not initialised in the constructor.\n", errout.str());
}
void initvar_nocopy() // ticket #2474
void initvar_nocopy1() // ticket #2474
{
check("class B\n"
"{\n"
@ -952,6 +953,41 @@ private:
"[test.cpp:7]: (warning) Member variable 'A::m_SemVar' is not assigned a value in 'A::operator='\n", errout.str());
}
void initvar_nocopy2() // ticket #2484
{
check("class B\n"
"{\n"
" B (B & Var);\n"
" B & operator= (const B & Var);\n"
"};\n"
"class A\n"
"{\n"
" B m_SemVar;\n"
"public:\n"
" A(){}\n"
" A(const A&){}\n"
" const A& operator=(const A&){return *this;}\n"
"};\n");
ASSERT_EQUALS("", errout.str());
check("class B\n"
"{\n"
"public:\n"
" B (B & Var);\n"
" B & operator= (const B & Var);\n"
"};\n"
"class A\n"
"{\n"
" B m_SemVar;\n"
"public:\n"
" A(){}\n"
" A(const A&){}\n"
" const A& operator=(const A&){return *this;}\n"
"};\n");
ASSERT_EQUALS("[test.cpp:12]: (warning) Member variable 'A::m_SemVar' is not initialised in the constructor.\n"
"[test.cpp:13]: (warning) Member variable 'A::m_SemVar' is not assigned a value in 'A::operator='\n", errout.str());
}
void initvar_destructor()
{
check("class Fred\n"