MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / checkCatchExceptionByValue

Method checkCatchExceptionByValue

lib/checkexceptionsafety.cpp:210–229  ·  view source on GitHub ↗

--------------------------------------------------------------------------- try {} catch (std::exception err) {} <- Should be "std::exception& err" ---------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

208// try {} catch (std::exception err) {} <- Should be "std::exception& err"
209//---------------------------------------------------------------------------
210void CheckExceptionSafetyImpl::checkCatchExceptionByValue()
211{
212 if (!mSettings.severity.isEnabled(Severity::style) && !mSettings.isPremiumEnabled("catchExceptionByValue"))
213 return;
214
215 logChecker("CheckExceptionSafety::checkCatchExceptionByValue"); // style
216
217 const SymbolDatabase* const symbolDatabase = mTokenizer->getSymbolDatabase();
218
219 for (const Scope &scope : symbolDatabase->scopeList) {
220 if (scope.type != ScopeType::eCatch)
221 continue;
222
223 // Find a pass-by-value declaration in the catch(), excluding basic types
224 // e.g. catch (std::exception err)
225 const Variable *var = scope.bodyStart->tokAt(-2)->variable();
226 if (var && var->isClass() && !var->isPointer() && !var->isReference())
227 catchExceptionByValueError(scope.classDef);
228 }
229}
230
231void CheckExceptionSafetyImpl::catchExceptionByValueError(const Token *tok)
232{

Callers 1

runChecksMethod · 0.80

Calls 5

isPremiumEnabledMethod · 0.80
variableMethod · 0.80
isClassMethod · 0.80
isEnabledMethod · 0.45
tokAtMethod · 0.45

Tested by

no test coverage detected