Ticket #2388. Added more detail to the 'exceptRethrowCopy' error message.

This commit is contained in:
Zachary Blair 2011-02-06 02:01:14 -08:00
parent daa04872a0
commit 44a350a6dc
2 changed files with 5 additions and 4 deletions

View File

@ -189,7 +189,7 @@ void CheckExceptionSafety::checkRethrowCopy()
const Token* rethrowTok = Token::findmatch(startBlockTok, "throw %varid%", endBlockTok, varid); const Token* rethrowTok = Token::findmatch(startBlockTok, "throw %varid%", endBlockTok, varid);
if (rethrowTok) if (rethrowTok)
{ {
rethrowCopyError(rethrowTok); rethrowCopyError(rethrowTok, startBlockTok->tokAt(-2)->str());
} }
tok = Token::findmatch(endBlockTok->next(), catchPattern); tok = Token::findmatch(endBlockTok->next(), catchPattern);

View File

@ -81,11 +81,12 @@ private:
reportError(tok, Severity::error, "exceptDeallocThrow", "Throwing exception in invalid state, " + varname + " points at deallocated memory"); 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", reportError(tok, Severity::style, "exceptRethrowCopy",
"Throwing a copy of the caught exception instead of rethrowing the original exception\n" "Throwing a copy of the caught exception instead of rethrowing the original exception\n"
"To rethrow the caught exception without unnecessary copying or slicing, use a bare 'throw;'. "); "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;'.");
} }
/** Generate all possible errors (for --errorlist) */ /** Generate all possible errors (for --errorlist) */
@ -94,7 +95,7 @@ private:
CheckExceptionSafety c(0, settings, errorLogger); CheckExceptionSafety c(0, settings, errorLogger);
c.destructorsError(0); c.destructorsError(0);
c.deallocThrowError(0, "p"); c.deallocThrowError(0, "p");
c.rethrowCopyError(0); c.rethrowCopyError(0, "varname");
} }
/** Short description of class (for --doc) */ /** Short description of class (for --doc) */