Skip to content

Commit

Permalink
Refactoring: Use NOEXCEPT for swap methods (danmar#6682)
Browse files Browse the repository at this point in the history
Misra C++ 2023 rule 18.4.1: Exception-unfriendly functions shall be
noexcept
  • Loading branch information
danmar committed Aug 11, 2024
1 parent c8cdd7a commit 11df5ae
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 7 deletions.
3 changes: 0 additions & 3 deletions cppcheckpremium-suppressions
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,6 @@ premium-misra-cpp-2023-18.1.1
# TODO do not throw token pointer?
premium-misra-cpp-2023-18.3.2:lib/tokenize.cpp

# TODO use noexcept
premium-misra-cpp-2023-18.4.1

# in smallvector we intentionally put a constant above some preprocessor includes
premium-misra-cpp-2023-19.0.3:lib/smallvector.h

Expand Down
2 changes: 1 addition & 1 deletion lib/checkleakautovar.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class CPPCHECKLIB VarInfo {
referenced.erase(varid);
}

void swap(VarInfo &other) {
void swap(VarInfo &other) NOEXCEPT {
alloctype.swap(other.alloctype);
possibleUsage.swap(other.possibleUsage);
conditionalAlloc.swap(other.conditionalAlloc);
Expand Down
2 changes: 1 addition & 1 deletion lib/programmemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ void ProgramMemory::erase_if(const std::function<bool(const ExprIdToken&)>& pred
}
}

void ProgramMemory::swap(ProgramMemory &pm)
void ProgramMemory::swap(ProgramMemory &pm) NOEXCEPT
{
mValues.swap(pm.mValues);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/programmemory.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ struct CPPCHECKLIB ProgramMemory {

void erase_if(const std::function<bool(const ExprIdToken&)>& pred);

void swap(ProgramMemory &pm);
void swap(ProgramMemory &pm) NOEXCEPT;

void clear();

Expand Down
2 changes: 1 addition & 1 deletion lib/valueptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class CPPCHECKLIB ValuePtr {
return get();
}

void swap(ValuePtr& rhs) {
void swap(ValuePtr& rhs) NOEXCEPT {
using std::swap;
swap(mPtr, rhs.mPtr);
swap(mClone, rhs.mClone);
Expand Down

0 comments on commit 11df5ae

Please sign in to comment.