simplifyTypedef: operator typedef. Ticket: #2375
This commit is contained in:
parent
8dae9bcbf7
commit
3f1f50e970
|
@ -528,32 +528,35 @@ 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()?
|
||||
else if (Token::Match(tok, "operator %any% %any% (") && Token::Match(tok->tokAt(3)->link(), ") const| ;|{|="))
|
||||
{
|
||||
// operator[] or operator()?
|
||||
if ((Token::simpleMatch(tok->next(), "( ) (") || Token::simpleMatch(tok->next(), "[ ] (")) &&
|
||||
Token::Match(tok->tokAt(3)->link(), ") const| ;|{|=|:"))
|
||||
{
|
||||
*funcStart = tok->next();
|
||||
*argStart = tok->tokAt(3);
|
||||
return true;
|
||||
}
|
||||
*funcStart = tok->next();
|
||||
*argStart = tok->tokAt(3);
|
||||
return true;
|
||||
}
|
||||
|
||||
// operator new/delete []?
|
||||
else if (Token::Match(tok->next(), "new|delete [ ] (") && Token::Match(tok->tokAt(4)->link(), ") ;|{"))
|
||||
{
|
||||
*funcStart = tok->next();
|
||||
*argStart = tok->tokAt(4);
|
||||
return true;
|
||||
}
|
||||
// operator new/delete []?
|
||||
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;
|
||||
|
|
|
@ -1643,30 +1643,38 @@ void Tokenizer::simplifyTypedef()
|
|||
}
|
||||
else if (ptrMember)
|
||||
{
|
||||
tok2->insertToken("(");
|
||||
tok2 = tok2->next();
|
||||
Token *tok3 = tok2;
|
||||
|
||||
const Token *tok4 = namespaceStart;
|
||||
|
||||
while (tok4 != namespaceEnd)
|
||||
if (Token::simpleMatch(tok2, "* ("))
|
||||
{
|
||||
tok2->insertToken(tok4->str());
|
||||
tok2->insertToken("*");
|
||||
tok2 = tok2->next();
|
||||
tok4 = tok4->next();
|
||||
}
|
||||
tok2->insertToken(namespaceEnd->str());
|
||||
tok2 = tok2->next();
|
||||
else
|
||||
{
|
||||
tok2->insertToken("(");
|
||||
tok2 = tok2->next();
|
||||
Token *tok3 = tok2;
|
||||
|
||||
tok2->insertToken("*");
|
||||
tok2 = tok2->next();
|
||||
const Token *tok4 = namespaceStart;
|
||||
|
||||
// skip over name
|
||||
tok2 = tok2->next();
|
||||
while (tok4 != namespaceEnd)
|
||||
{
|
||||
tok2->insertToken(tok4->str());
|
||||
tok2 = tok2->next();
|
||||
tok4 = tok4->next();
|
||||
}
|
||||
tok2->insertToken(namespaceEnd->str());
|
||||
tok2 = tok2->next();
|
||||
|
||||
tok2->insertToken(")");
|
||||
tok2 = tok2->next();
|
||||
Token::createMutualLinks(tok2, tok3);
|
||||
tok2->insertToken("*");
|
||||
tok2 = tok2->next();
|
||||
|
||||
// skip over name
|
||||
tok2 = tok2->next();
|
||||
|
||||
tok2->insertToken(")");
|
||||
tok2 = tok2->next();
|
||||
Token::createMutualLinks(tok2, tok3);
|
||||
}
|
||||
}
|
||||
else if (typeOf)
|
||||
{
|
||||
|
|
|
@ -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