From 65eed83cabfe9746c444bf50c4de5bdcc5d94592 Mon Sep 17 00:00:00 2001 From: Xav83 Date: Tue, 10 Oct 2023 07:36:11 +0200 Subject: [PATCH 1/4] Corrects a clang-tidy warning about the use of 'constexpr' for constant variables instead of macros: avogadro/core/atomutilities.cpp:12:9: warning: macro 'M_TETRAHED' used to declare a constant; consider using a 'constexpr' constant [cppcoreguidelines-macro-usage] ^ Signed-off-by: Xav83 --- avogadro/core/atomutilities.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/avogadro/core/atomutilities.cpp b/avogadro/core/atomutilities.cpp index 9c0f43e8ba..4a7e182e17 100644 --- a/avogadro/core/atomutilities.cpp +++ b/avogadro/core/atomutilities.cpp @@ -9,7 +9,7 @@ #include #include -#define M_TETRAHED 109.47122063449069389 +constexpr double M_TETRAHED = 109.47122063449069389; namespace Avogadro::Core { From c55703131e69fd8b36d9bb6694be6bbed698caac Mon Sep 17 00:00:00 2001 From: Xav83 Date: Tue, 10 Oct 2023 07:39:55 +0200 Subject: [PATCH 2/4] Corrects a clang-tidy warning about the use of 'using' instead of 'typedef' for aliases: /home/runner/work/avogadrolibs/avogadrolibs/avogadrolibs/avogadro/core/atomutilities.cpp:16:1: warning: use 'using' instead of 'typedef' [modernize-use-using] typedef Array NeighborListType; ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ using NeighborListType = Array Signed-off-by: Xav83 --- avogadro/core/atomutilities.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/avogadro/core/atomutilities.cpp b/avogadro/core/atomutilities.cpp index 4a7e182e17..2c6140ac3c 100644 --- a/avogadro/core/atomutilities.cpp +++ b/avogadro/core/atomutilities.cpp @@ -13,7 +13,7 @@ constexpr double M_TETRAHED = 109.47122063449069389; namespace Avogadro::Core { -typedef Array NeighborListType; +using NeighborListType = Array; inline unsigned int countExistingBonds(const NeighborListType& bonds) { From 3698e0592ffd68f1bff812002ca35eedb8e0c86a Mon Sep 17 00:00:00 2001 From: Xav83 Date: Tue, 10 Oct 2023 07:45:41 +0200 Subject: [PATCH 3/4] Corrects some clang-tidy warnings about variables which can be declared as const references to avoid unecessary copy initialization: /home/runner/work/avogadrolibs/avogadrolibs/avogadrolibs/avogadro/core/atomutilities.cpp:78:13: warning: the variable 'bond1' is copy-constructed from a const reference but is only used as const reference; consider making it a const reference [performance-unnecessary-copy-initialization] Vector3 bond1 = allVectors[0]; ^ const & /home/runner/work/avogadrolibs/avogadrolibs/avogadrolibs/avogadro/core/atomutilities.cpp:150:13: warning: the variable 'bond1' is copy-constructed from a const reference but is only used as const reference; consider making it a const reference [performance-unnecessary-copy-initialization] Vector3 bond1 = allVectors[0]; ^ const & /home/runner/work/avogadrolibs/avogadrolibs/avogadrolibs/avogadro/core/atomutilities.cpp:151:13: warning: the variable 'bond2' is copy-constructed from a const reference but is only used as const reference; consider making it a const reference [performance-unnecessary-copy-initialization] Vector3 bond2 = allVectors[1]; ^ const & /home/runner/work/avogadrolibs/avogadrolibs/avogadrolibs/avogadro/core/atomutilities.cpp:173:13: warning: the variable 'bond1' is copy-constructed from a const reference but is only used as const reference; consider making it a const reference [performance-unnecessary-copy-initialization] Vector3 bond1 = allVectors[0]; ^ const & /home/runner/work/avogadrolibs/avogadrolibs/avogadrolibs/avogadro/core/atomutilities.cpp:174:13: warning: the variable 'bond2' is copy-constructed from a const reference but is only used as const reference; consider making it a const reference [performance-unnecessary-copy-initialization] Vector3 bond2 = allVectors[1]; ^ const & /home/runner/work/avogadrolibs/avogadrolibs/avogadrolibs/avogadro/core/atomutilities.cpp:175:13: warning: the variable 'bond3' is copy-constructed from a const reference but is only used as const reference; consider making it a const reference [performance-unnecessary-copy-initialization] Vector3 bond3 = allVectors[2]; ^ const & Signed-off-by: Xav83 --- avogadro/core/atomutilities.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/avogadro/core/atomutilities.cpp b/avogadro/core/atomutilities.cpp index 2c6140ac3c..1bf4e948dd 100644 --- a/avogadro/core/atomutilities.cpp +++ b/avogadro/core/atomutilities.cpp @@ -75,7 +75,7 @@ Vector3 AtomUtilities::generateNewBondVector( return newPos; } else if (currentValence == 1) { // One bonded atom - Vector3 bond1 = allVectors[0]; + const Vector3& bond1 = allVectors[0]; // Check what's attached to our neighbor -- we want to set trans to the // neighbor @@ -147,8 +147,8 @@ Vector3 AtomUtilities::generateNewBondVector( return -1.0 * newPos.normalized(); } // end one bond else if (currentValence == 2) { - Vector3 bond1 = allVectors[0]; - Vector3 bond2 = allVectors[1]; + const Vector3& bond1 = allVectors[0]; + const Vector3& bond2 = allVectors[1]; Vector3 v1 = bond1 + bond2; v1.normalize(); @@ -170,9 +170,9 @@ Vector3 AtomUtilities::generateNewBondVector( return -1.0 * newPos.normalized(); } // end two bonds else if (currentValence == 3) { - Vector3 bond1 = allVectors[0]; - Vector3 bond2 = allVectors[1]; - Vector3 bond3 = allVectors[2]; + const Vector3& bond1 = allVectors[0]; + const Vector3& bond2 = allVectors[1]; + const Vector3& bond3 = allVectors[2]; // need to handle different hybridizations here From 7552ce23c70249dc6f3792eb812edf3312d0db1f Mon Sep 17 00:00:00 2001 From: Xav83 Date: Tue, 10 Oct 2023 07:50:50 +0200 Subject: [PATCH 4/4] Corrects a clang-tidy warning about an implicit narrowing conversion from 'std::size_t' to 'int': /home/runner/work/avogadrolibs/avogadrolibs/avogadrolibs/avogadro/core/atomutilities.cpp:70:24: warning: narrowing conversion from 'std::vector::size_type' (aka 'unsigned long') to signed type 'int' is implementation-defined [bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions] int currentValence = allVectors.size(); ^ Signed-off-by: Xav83 --- avogadro/core/atomutilities.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/avogadro/core/atomutilities.cpp b/avogadro/core/atomutilities.cpp index 1bf4e948dd..5d37940964 100644 --- a/avogadro/core/atomutilities.cpp +++ b/avogadro/core/atomutilities.cpp @@ -67,7 +67,7 @@ Vector3 AtomUtilities::generateNewBondVector( { Vector3 newPos; bool success = false; - int currentValence = allVectors.size(); + int currentValence = static_cast(allVectors.size()); // No bonded atoms, just pick a random vector if (currentValence == 0) {