From 9e61e7dda86a8cf7b66f26843e7ff664222646b4 Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Wed, 17 Feb 2010 22:46:03 +0100 Subject: [PATCH] Fixed #1405 (false positive: operator = should return reference t --- lib/checkclass.cpp | 4 ++-- test/testclass.cpp | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 7a24ae487..81aa25d89 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -924,7 +924,7 @@ void CheckClass::operatorEqRetRefThis() // check for return of reference to this if (tok1->str() == "return") { - if (!(Token::Match(tok1->tokAt(1), "* this ;") || + if (!(Token::Match(tok1->tokAt(1), "(| * this ;|=") || Token::Match(tok1->tokAt(1), "operator = ("))) operatorEqRetRefThisError(tok); } @@ -976,7 +976,7 @@ void CheckClass::operatorEqRetRefThis() // check for return of reference to this if (tok1->str() == "return") { - if (!(Token::Match(tok1->tokAt(1), "* this ;") || + if (!(Token::Match(tok1->tokAt(1), "(| * this ;|=") || Token::Match(tok1->tokAt(1), "operator = ("))) operatorEqRetRefThisError(tok); } diff --git a/test/testclass.cpp b/test/testclass.cpp index 0ce0462dc..6c02b17a9 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -71,6 +71,7 @@ private: TEST_CASE(operatorEq1); TEST_CASE(operatorEqRetRefThis1); TEST_CASE(operatorEqRetRefThis2); // ticket #1323 + TEST_CASE(operatorEqRetRefThis3); // ticket #1405 TEST_CASE(operatorEqToSelf1); // single class TEST_CASE(operatorEqToSelf2); // nested class TEST_CASE(operatorEqToSelf3); // multiple inheritance @@ -295,6 +296,18 @@ private: ASSERT_EQUALS("", errout.str()); } + void operatorEqRetRefThis3() + { + // ticket # 1405 + checkOpertorEqRetRefThis( + "class A {\n" + "public:\n" + " inline A &operator =(int *other) { return (*this;) };\n" + " inline A &operator =(long *other) { return (*this = 0;) };\n" + "};"); + ASSERT_EQUALS("", errout.str()); + } + // Check that operator Equal checks for assignment to self void checkOpertorEqToSelf(const char code[]) {