simplifyTypedef: operator typedef. Ticket: #2375
This commit is contained in:
parent
8dae9bcbf7
commit
3f1f50e970
|
@ -528,19 +528,15 @@ bool SymbolDatabase::isFunction(const Token *tok, const Token **funcStart, const
|
|||
}
|
||||
|
||||
// simple operator?
|
||||
else if (Token::Match(tok, "operator %any% (") && Token::Match(tok->tokAt(2)->link(), ") const| ;|{|=|:"))
|
||||
else if (Token::Match(tok, "operator %any% (") && Token::Match(tok->tokAt(2)->link(), ") const| ;|{|="))
|
||||
{
|
||||
*funcStart = tok->next();
|
||||
*argStart = tok->tokAt(2);
|
||||
return true;
|
||||
}
|
||||
|
||||
// complex operator?
|
||||
else if (tok->str() == "operator")
|
||||
{
|
||||
// operator[] or operator()?
|
||||
if ((Token::simpleMatch(tok->next(), "( ) (") || Token::simpleMatch(tok->next(), "[ ] (")) &&
|
||||
Token::Match(tok->tokAt(3)->link(), ") const| ;|{|=|:"))
|
||||
else if (Token::Match(tok, "operator %any% %any% (") && Token::Match(tok->tokAt(3)->link(), ") const| ;|{|="))
|
||||
{
|
||||
*funcStart = tok->next();
|
||||
*argStart = tok->tokAt(3);
|
||||
|
@ -548,12 +544,19 @@ bool SymbolDatabase::isFunction(const Token *tok, const Token **funcStart, const
|
|||
}
|
||||
|
||||
// operator new/delete []?
|
||||
else if (Token::Match(tok->next(), "new|delete [ ] (") && Token::Match(tok->tokAt(4)->link(), ") ;|{"))
|
||||
else if (Token::Match(tok, "operator %any% %any% %any% (") && Token::Match(tok->tokAt(4)->link(), ") const| ;|{|="))
|
||||
{
|
||||
*funcStart = tok->next();
|
||||
*argStart = tok->tokAt(4);
|
||||
return true;
|
||||
}
|
||||
|
||||
// complex user defined operator?
|
||||
else if (Token::Match(tok, "operator %any% %any% %any% %any% (") && Token::Match(tok->tokAt(5)->link(), ") const| ;|{|="))
|
||||
{
|
||||
*funcStart = tok->next();
|
||||
*argStart = tok->tokAt(5);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
|
@ -1642,6 +1642,13 @@ void Tokenizer::simplifyTypedef()
|
|||
Token::createMutualLinks(tok2->next(), tok3);
|
||||
}
|
||||
else if (ptrMember)
|
||||
{
|
||||
if (Token::simpleMatch(tok2, "* ("))
|
||||
{
|
||||
tok2->insertToken("*");
|
||||
tok2 = tok2->next();
|
||||
}
|
||||
else
|
||||
{
|
||||
tok2->insertToken("(");
|
||||
tok2 = tok2->next();
|
||||
|
@ -1668,6 +1675,7 @@ void Tokenizer::simplifyTypedef()
|
|||
tok2 = tok2->next();
|
||||
Token::createMutualLinks(tok2, tok3);
|
||||
}
|
||||
}
|
||||
else if (typeOf)
|
||||
{
|
||||
tok2->insertToken("(");
|
||||
|
|
|
@ -162,6 +162,7 @@ private:
|
|||
TEST_CASE(constoperator1); // operator< can often be const
|
||||
TEST_CASE(constoperator2); // operator<<
|
||||
TEST_CASE(constoperator3);
|
||||
TEST_CASE(constoperator4);
|
||||
TEST_CASE(constincdec); // increment/decrement => non-const
|
||||
TEST_CASE(constReturnReference);
|
||||
TEST_CASE(constDelete); // delete member variable => not const
|
||||
|
@ -3414,6 +3415,23 @@ private:
|
|||
ASSERT_EQUALS("[test.cpp:3]: (information) Technically the member function 'Fred::operator[]' can be const.\n", errout.str());
|
||||
}
|
||||
|
||||
void constoperator4()
|
||||
{
|
||||
checkConst("struct Fred {\n"
|
||||
" int array[10];\n"
|
||||
" typedef int* (Fred::*UnspecifiedBoolType);\n"
|
||||
" operator UnspecifiedBoolType() { };\n"
|
||||
"};\n");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (information) Technically the member function 'Fred::int' can be const.\n", errout.str());
|
||||
|
||||
checkConst("struct Fred {\n"
|
||||
" int array[10];\n"
|
||||
" typedef int* (Fred::*UnspecifiedBoolType);\n"
|
||||
" operator UnspecifiedBoolType() { array[0] = 0; };\n"
|
||||
"};\n");
|
||||
TODO_ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void const5()
|
||||
{
|
||||
// ticket #1482
|
||||
|
|
Loading…
Reference in New Issue