Formatted the code [ci skip]

This commit is contained in:
orbitcowboy 2021-06-02 16:59:34 +02:00
parent 397806b419
commit 14ff646c92
1 changed files with 16 additions and 9 deletions

View File

@ -72,7 +72,8 @@ void CheckExceptionSafety::destructors()
}
}
void CheckExceptionSafety::destructorsError(const Token * const tok, const std::string &className) {
void CheckExceptionSafety::destructorsError(const Token * const tok, const std::string &className)
{
reportError(tok, Severity::warning, "exceptThrowInDestructor",
"Class " + className + " is not safe, destructor throws exception\n"
"The class " + className + " is not safe because its destructor "
@ -142,7 +143,8 @@ void CheckExceptionSafety::deallocThrow()
}
}
void CheckExceptionSafety::deallocThrowError(const Token * const tok, const std::string &varname) {
void CheckExceptionSafety::deallocThrowError(const Token * const tok, const std::string &varname)
{
reportError(tok, Severity::warning, "exceptDeallocThrow", "Exception thrown in invalid state, '" +
varname + "' points at deallocated memory.", CWE398, Certainty::normal);
}
@ -184,7 +186,8 @@ void CheckExceptionSafety::checkRethrowCopy()
}
}
void CheckExceptionSafety::rethrowCopyError(const Token * const tok, const std::string &varname) {
void CheckExceptionSafety::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 + ";' creates an unnecessary copy of '" + varname + "'. "
@ -213,7 +216,8 @@ void CheckExceptionSafety::checkCatchExceptionByValue()
}
}
void CheckExceptionSafety::catchExceptionByValueError(const Token *tok) {
void CheckExceptionSafety::catchExceptionByValueError(const Token *tok)
{
reportError(tok, Severity::style,
"catchExceptionByValue", "Exception should be caught by reference.\n"
"The exception is caught by value. It could be caught "
@ -298,7 +302,8 @@ void CheckExceptionSafety::nothrowThrows()
}
}
void CheckExceptionSafety::noexceptThrowError(const Token * const tok) {
void CheckExceptionSafety::noexceptThrowError(const Token * const tok)
{
reportError(tok, Severity::error, "throwInNoexceptFunction", "Exception thrown in function declared not to throw exceptions.", CWE398, Certainty::normal);
}
@ -334,7 +339,8 @@ void CheckExceptionSafety::unhandledExceptionSpecification()
}
}
void CheckExceptionSafety::unhandledExceptionSpecificationError(const Token * const tok1, const Token * const tok2, const std::string & funcname) {
void CheckExceptionSafety::unhandledExceptionSpecificationError(const Token * const tok1, const Token * const tok2, const std::string & funcname)
{
const std::string str1(tok1 ? tok1->str() : "foo");
const std::list<const Token*> locationList = { tok1, tok2 };
reportError(locationList, Severity::style, "unhandledExceptionSpecification",
@ -357,11 +363,11 @@ void CheckExceptionSafety::rethrowNoCurrentException()
// Rethrow can be used in 'exception dispatcher' idiom which is FP in such case
// https://isocpp.org/wiki/faq/exceptions#throw-without-an-object
// We check the beggining of the function with idiom pattern
if (Token::simpleMatch(function->functionScope->bodyStart->next(), "try { throw ; } catch (" ))
if (Token::simpleMatch(function->functionScope->bodyStart->next(), "try { throw ; } catch ("))
continue;
for (const Token *tok = function->functionScope->bodyStart->next();
tok != function->functionScope->bodyEnd; tok = tok->next()) {
tok != function->functionScope->bodyEnd; tok = tok->next()) {
if (Token::simpleMatch(tok, "catch (")) {
tok = tok->linkAt(1); // skip catch argument
if (Token::simpleMatch(tok, ") {"))
@ -376,7 +382,8 @@ void CheckExceptionSafety::rethrowNoCurrentException()
}
}
void CheckExceptionSafety::rethrowNoCurrentExceptionError(const Token *tok) {
void CheckExceptionSafety::rethrowNoCurrentExceptionError(const Token *tok)
{
reportError(tok, Severity::error, "rethrowNoCurrentException",
"Rethrowing current exception with 'throw;', it seems there is no current exception to rethrow."
" If there is no current exception this calls std::terminate()."