From fa868e44ae2827f2efb2b5d3c2d5e7462295545e Mon Sep 17 00:00:00 2001 From: Greg Hewgill Date: Tue, 15 Mar 2011 20:19:30 +1300 Subject: [PATCH] Support use of 'this->' when checking operator=() return type --- lib/checkclass.cpp | 1 + test/testclass.cpp | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index e8d13cdff..d917ed8ce 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -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); diff --git a/test/testclass.cpp b/test/testclass.cpp index 2259a8071..45a9f22a7 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -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()