From 11df5ae6f3a89b31e45a1083909b48298334c3d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 11 Aug 2024 20:40:13 +0200 Subject: [PATCH] Refactoring: Use NOEXCEPT for swap methods (#6682) Misra C++ 2023 rule 18.4.1: Exception-unfriendly functions shall be noexcept --- cppcheckpremium-suppressions | 3 --- lib/checkleakautovar.h | 2 +- lib/programmemory.cpp | 2 +- lib/programmemory.h | 2 +- lib/valueptr.h | 2 +- 5 files changed, 4 insertions(+), 7 deletions(-) diff --git a/cppcheckpremium-suppressions b/cppcheckpremium-suppressions index 7ea4ec12398..2bbbe61e71c 100644 --- a/cppcheckpremium-suppressions +++ b/cppcheckpremium-suppressions @@ -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 diff --git a/lib/checkleakautovar.h b/lib/checkleakautovar.h index 5bcb42e5746..0cd9e4abdaa 100644 --- a/lib/checkleakautovar.h +++ b/lib/checkleakautovar.h @@ -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); diff --git a/lib/programmemory.cpp b/lib/programmemory.cpp index 1e7ba3323d6..af86ef98318 100644 --- a/lib/programmemory.cpp +++ b/lib/programmemory.cpp @@ -184,7 +184,7 @@ void ProgramMemory::erase_if(const std::function& pred } } -void ProgramMemory::swap(ProgramMemory &pm) +void ProgramMemory::swap(ProgramMemory &pm) NOEXCEPT { mValues.swap(pm.mValues); } diff --git a/lib/programmemory.h b/lib/programmemory.h index 505cc8e3230..5d8b2632908 100644 --- a/lib/programmemory.h +++ b/lib/programmemory.h @@ -124,7 +124,7 @@ struct CPPCHECKLIB ProgramMemory { void erase_if(const std::function& pred); - void swap(ProgramMemory &pm); + void swap(ProgramMemory &pm) NOEXCEPT; void clear(); diff --git a/lib/valueptr.h b/lib/valueptr.h index 69869e0532d..28ab2a45544 100644 --- a/lib/valueptr.h +++ b/lib/valueptr.h @@ -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);