Merge pull request #692 from simartin/ticket_7017

Ticket #7017: Properly interpret operator= return type for template classes in CheckClass::operatorEq.
This commit is contained in:
amai2012 2015-10-03 10:24:07 +02:00
commit 6f72b97e96
2 changed files with 19 additions and 1 deletions

View File

@ -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<template_parameters>&""
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" &&

View File

@ -699,6 +699,13 @@ private:
" void operator=(const A&)=delete;\n"
"};");
ASSERT_EQUALS("", errout.str());
// Ticket #7017
checkOpertorEq("template<class T> struct X {\n"
" inline X(const X& Rhs);\n"
" inline X<T>& operator =(const X& Rhs);\n"
"};");
ASSERT_EQUALS("", errout.str());
}
void operatorEq2() {