From 0f7e20c11d6c13d8255fe326cc2c394e3b8405b7 Mon Sep 17 00:00:00 2001 From: Simon Martin Date: Fri, 2 Oct 2015 23:23:44 +0200 Subject: [PATCH] Ticket #7017: Properly interpret operator= return type for template classes in CheckClass::operatorEq. --- lib/checkclass.cpp | 13 ++++++++++++- test/testclass.cpp | 7 +++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 8ab9620a0..87c97521e 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -1188,7 +1188,18 @@ void CheckClass::operatorEq() if (func->isDelete()) continue; // use definition for check so we don't have to deal with qualification - if (!(Token::Match(func->retDef, "%type% &") && func->retDef->str() == scope->className)) { + bool returnSelfRef = false; + if (func->retDef->str() == scope->className) { + if (Token::Match(func->retDef, "%type% &")) { + returnSelfRef = true; + } else { + // We might have "Self&"" + Token *tok = func->retDef->next(); + if (tok && tok->str() == "<" && tok->link() && tok->link()->next() && tok->link()->next()->str() == "&") + returnSelfRef = true; + } + } + if (!returnSelfRef) { // make sure we really have a copy assignment operator if (Token::Match(func->tokenDef->tokAt(2), "const| %name% &")) { if (func->tokenDef->strAt(2) == "const" && diff --git a/test/testclass.cpp b/test/testclass.cpp index a4a62fd9b..57d89033e 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -699,6 +699,13 @@ private: " void operator=(const A&)=delete;\n" "};"); ASSERT_EQUALS("", errout.str()); + + // Ticket #7017 + checkOpertorEq("template struct X {\n" + " inline X(const X& Rhs);\n" + " inline X& operator =(const X& Rhs);\n" + "};"); + ASSERT_EQUALS("", errout.str()); } void operatorEq2() {