Support use of 'this->' when checking operator=() return type

This commit is contained in:
Greg Hewgill 2011-03-15 20:19:30 +13:00
parent e1afd5eb09
commit fa868e44ae
2 changed files with 11 additions and 0 deletions

View File

@ -924,6 +924,7 @@ void CheckClass::checkReturnPtrThis(const Scope *scope, const Function *func, co
else if (!(Token::Match(tok->tokAt(1), "(| * this ;|=") ||
Token::Match(tok->tokAt(1), "(| * this +=") ||
Token::simpleMatch(tok->tokAt(1), "operator= (") ||
Token::simpleMatch(tok->tokAt(1), "this . operator= (") ||
(Token::Match(tok->tokAt(1), "%type% :: operator= (") &&
tok->next()->str() == scope->className)))
operatorEqRetRefThisError(func->token);

View File

@ -452,6 +452,16 @@ private:
"A &A::operator =(int *other) { return (*this;) };\n"
"A &A::operator =(long *other) { return operator = (*(int *)other); };");
ASSERT_EQUALS("", errout.str());
checkOpertorEqRetRefThis(
"class A {\n"
"public:\n"
" A &operator =(int *other);\n"
" A &operator =(long *other);\n"
"};\n"
"A &A::operator =(int *other) { return (*this;) };\n"
"A &A::operator =(long *other) { return this->operator = (*(int *)other); };");
ASSERT_EQUALS("", errout.str());
}
void operatorEqRetRefThis4()