Ticket #2388. Added more detail to the 'exceptRethrowCopy' error message.
This commit is contained in:
parent
daa04872a0
commit
44a350a6dc
|
@ -189,7 +189,7 @@ void CheckExceptionSafety::checkRethrowCopy()
|
|||
const Token* rethrowTok = Token::findmatch(startBlockTok, "throw %varid%", endBlockTok, varid);
|
||||
if (rethrowTok)
|
||||
{
|
||||
rethrowCopyError(rethrowTok);
|
||||
rethrowCopyError(rethrowTok, startBlockTok->tokAt(-2)->str());
|
||||
}
|
||||
|
||||
tok = Token::findmatch(endBlockTok->next(), catchPattern);
|
||||
|
|
|
@ -81,10 +81,11 @@ private:
|
|||
reportError(tok, Severity::error, "exceptDeallocThrow", "Throwing exception in invalid state, " + varname + " points at deallocated memory");
|
||||
}
|
||||
|
||||
void rethrowCopyError(const Token * const tok)
|
||||
void rethrowCopyError(const Token * const tok, const std::string &varname)
|
||||
{
|
||||
reportError(tok, Severity::style, "exceptRethrowCopy",
|
||||
"Throwing a copy of the caught exception instead of rethrowing the original exception\n"
|
||||
"Rethrowing an exception with 'throw " + varname + ";' makes an unnecessary copy of '" + varname + "'.\n"
|
||||
"To rethrow the caught exception without unnecessary copying or slicing, use a bare 'throw;'.");
|
||||
}
|
||||
|
||||
|
@ -94,7 +95,7 @@ private:
|
|||
CheckExceptionSafety c(0, settings, errorLogger);
|
||||
c.destructorsError(0);
|
||||
c.deallocThrowError(0, "p");
|
||||
c.rethrowCopyError(0);
|
||||
c.rethrowCopyError(0, "varname");
|
||||
}
|
||||
|
||||
/** Short description of class (for --doc) */
|
||||
|
|
Loading…
Reference in New Issue