clang-tidy-11 fixes for utils
authorJoe Jordan <ejjordan12@gmail.com>
Tue, 20 Apr 2021 09:18:07 +0000 (09:18 +0000)
committerAndrey Alekseenko <al42and@gmail.com>
Tue, 20 Apr 2021 09:18:07 +0000 (09:18 +0000)
src/gromacs/utility/cstringutil.cpp
src/gromacs/utility/enumerationhelpers.h
src/gromacs/utility/fatalerror.cpp
src/gromacs/utility/futil.cpp
src/gromacs/utility/keyvaluetree.cpp
src/gromacs/utility/keyvaluetreeserializer.cpp
src/gromacs/utility/keyvaluetreetransform.cpp
src/gromacs/utility/programcontext.cpp
src/gromacs/utility/smalloc.cpp
src/gromacs/utility/tests/.clang-tidy [new file with mode: 0644]

index 161fb7396eecb30393f43d60d54e165c253017cb..dbefa55d97b7249761af084e4db8f2b36b691d36 100644 (file)
@@ -298,7 +298,7 @@ const unsigned int gmx_string_hash_init = 5381;
 
 unsigned int gmx_string_fullhash_func(const char* s, unsigned int hash_init)
 {
-    int c = 0;
+    char c = 0;
 
     while ((c = (*s++)) != '\0')
     {
index e2352b2421aaf436d0a415df0691d2de2c55737d..b30c8fee7a90f820d79c22410269fd6c3011ac52 100644 (file)
@@ -200,7 +200,7 @@ public:
  * \tparam  ArraySize  Size in entries of the array.
  */
 template<typename EnumType, typename DataType, EnumType ArraySize = EnumType::Count>
-struct EnumerationArray final
+struct EnumerationArray final // NOLINT
 {
     //! Convenience alias
     using EnumerationWrapperType = EnumerationWrapper<EnumType, ArraySize>;
index a9d416459e684fd6283bb32929db8bad153a40fd..a8eb96e755e1a6effdfe8cb2f238674a27894277 100644 (file)
 
 #include "errorformat.h"
 
-static bool bDebug = false;
+static bool bDebug = false; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
 
-FILE*    debug        = nullptr;
-gmx_bool gmx_debug_at = FALSE;
+FILE* debug        = nullptr; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
+bool  gmx_debug_at = false;   // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
 
-static FILE*      log_file = nullptr;
-static std::mutex error_mutex;
+static FILE*      log_file = nullptr; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
+static std::mutex error_mutex;        // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
 
 using Lock = std::lock_guard<std::mutex>;
 
@@ -112,6 +112,7 @@ static void default_error_handler(const char* title, const std::string& msg, con
     gmx::internal::printFatalErrorFooter(stderr);
 }
 
+// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
 static gmx_error_handler_t gmx_error_handler = default_error_handler;
 
 void gmx_set_error_handler(gmx_error_handler_t func)
index 95a0eaa04c249a7a982f9b8914a73a637db50200..8a54e0d864093fe150f932176e41ee495ee03b9c 100644 (file)
@@ -82,12 +82,16 @@ typedef struct t_pstack
     struct t_pstack* prev;
 } t_pstack;
 
-static t_pstack* pstack           = nullptr;
-static bool      bUnbuffered      = false;
-static int       s_maxBackupCount = 0;
+// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
+static t_pstack* pstack = nullptr;
+// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
+static bool bUnbuffered = false;
+// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
+static int s_maxBackupCount = 0;
 
 /* this linked list is an intrinsically globally shared object, so we have
    to protect it with mutexes */
+// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
 static std::mutex pstack_mutex;
 
 using Lock = std::lock_guard<std::mutex>;
@@ -97,7 +101,7 @@ namespace gmx
 namespace
 {
 //! Global library file finder; stores the object set with setLibraryFileFinder().
-const DataFileFinder* g_libFileFinder;
+const DataFileFinder* g_libFileFinder; //NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
 //! Default library file finder if nothing is set.
 const DataFileFinder g_defaultLibFileFinder;
 } // namespace
index 774af0a3667c7acddd9caab4c0e248baf8de89f9..028939954fd02c174433e7aa8fe0becafc6976cf 100644 (file)
@@ -174,7 +174,6 @@ public:
         abstol_(abstol)
     {
     }
-
     void compareObjects(const KeyValueTreeObject& obj1, const KeyValueTreeObject& obj2)
     {
         for (const auto& prop1 : obj1.properties())
index c111a78998f5f9255d507d1eb94b6d31bde815c8..3395bb2371dda3ca1e847572787f2020eb10283c 100644 (file)
@@ -68,14 +68,19 @@ private:
         SerializerFunction   serialize;
         DeserializerFunction deserialize;
     };
-
-    static std::mutex                                    s_initMutex;
-    static std::map<std::type_index, Serializer>         s_serializers;
+    // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
+    static std::mutex s_initMutex;
+    // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
+    static std::map<std::type_index, Serializer> s_serializers;
+    // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
     static std::map<unsigned char, DeserializerFunction> s_deserializers;
 };
 
-std::mutex                                                     ValueSerializer::s_initMutex;
-std::map<std::type_index, ValueSerializer::Serializer>         ValueSerializer::s_serializers;
+// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
+std::mutex ValueSerializer::s_initMutex;
+// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
+std::map<std::type_index, ValueSerializer::Serializer> ValueSerializer::s_serializers;
+// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
 std::map<unsigned char, ValueSerializer::DeserializerFunction> ValueSerializer::s_deserializers;
 
 template<typename T>
index 45ac7b87237b1abe0317d9a1b407cc74ddc006df..6c72642c69b995f91a6fbf0d5e77753fde72eca0 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2016,2017,2018,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2016,2017,2018,2019,2020,2021, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
index acc70d8d1586d1b0a37599de5e4a027c0668eea6..020c9c93358b4b113c81ecb12d56bf38275c8101 100644 (file)
@@ -2,7 +2,7 @@
  * This file is part of the GROMACS molecular simulation package.
  *
  * Copyright (c) 2013,2014,2015,2017,2018 by the GROMACS development team.
- * Copyright (c) 2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2019,2020,2021, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -79,6 +79,7 @@ public:
 };
 
 //! Global program info; stores the object set with setProgramContext().
+// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
 const IProgramContext* g_programContext;
 //! Default program context if nothing is set.
 const DefaultProgramContext g_defaultContext;
index 190fb2a7f1fc16e025ee2a78ccfd64bd86483953..ff5128030663010cf50d9663585a2594593c0ed3 100644 (file)
@@ -56,7 +56,9 @@
 #    include "gromacs/utility/gmxmpi.h"
 #endif
 
-static bool       g_bOverAllocDD = false;
+// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
+static bool g_bOverAllocDD = false;
+// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
 static std::mutex g_overAllocMutex;
 
 void* save_malloc(const char* name, const char* file, int line, size_t size)
diff --git a/src/gromacs/utility/tests/.clang-tidy b/src/gromacs/utility/tests/.clang-tidy
new file mode 100644 (file)
index 0000000..0adf51e
--- /dev/null
@@ -0,0 +1,91 @@
+# List of rationales for check suppressions (where known).
+# This have to precede the list because inline comments are not
+# supported by clang-tidy.
+#
+#         -cppcoreguidelines-non-private-member-variables-in-classes,
+#         -misc-non-private-member-variables-in-classes,
+# We intend a gradual transition to conform to this guideline, but it
+# is not practical to implement yet.
+#
+#         -readability-isolate-declaration,
+# Declarations like "int a, b;" are readable. Some forms are not, and
+# those might reasonably be suggested against during code review.
+#
+#         -cppcoreguidelines-avoid-c-arrays,
+# C arrays are still necessary in many places with legacy code
+#
+#         -cppcoreguidelines-avoid-magic-numbers,
+#         -readability-magic-numbers,
+# We have many legitimate use cases for magic numbers
+#
+#         -cppcoreguidelines-macro-usage,
+# We do use too many macros, and we should fix many of them, but there
+# is no reasonable way to suppress the check e.g. in src/config.h and
+# configuring the build is a major legitimate use of macros.
+#
+#         -cppcoreguidelines-narrowing-conversions,
+#         -bugprone-narrowing-conversions
+# We have many cases where int is converted to float and we don't care
+# enough about such potential loss of precision to use explicit casts
+# in large numbers of places.
+#
+#         -google-readability-avoid-underscore-in-googletest-name
+# We need to use underscores for readability for our legacy types
+# and command-line parameter names
+#
+#         -misc-no-recursion
+# We have way too many functions and methods relying on recursion
+#
+#         -cppcoreguidelines-avoid-non-const-global-variables
+# There are quite a lot of static variables in the test code that
+# can not be replaced.
+#
+#         -modernize-avoid-bind
+# Some code needs to use std::bind and can't be modernized quickly.
+Checks:  clang-diagnostic-*,-clang-analyzer-*,-clang-analyzer-security.insecureAPI.strcpy,
+         bugprone-*,misc-*,readability-*,performance-*,mpi-*,
+         -readability-inconsistent-declaration-parameter-name,
+         -readability-function-size,-readability-else-after-return,
+         modernize-use-nullptr,modernize-use-emplace,
+         modernize-make-unique,modernize-make-shared,
+         modernize-avoid-bind,
+         modernize-use-override,
+         modernize-redundant-void-arg,modernize-use-bool-literals,
+         cppcoreguidelines-*,-cppcoreguidelines-pro-*,-cppcoreguidelines-owning-memory,
+         -cppcoreguidelines-no-malloc,-cppcoreguidelines-special-member-functions,
+         -cppcoreguidelines-avoid-goto,
+         google-*,-google-build-using-namespace,-google-explicit-constructor,
+         -google-readability-function-size,-google-readability-todo,-google-runtime-int,
+         -cppcoreguidelines-non-private-member-variables-in-classes,
+         -misc-non-private-member-variables-in-classes,
+         -readability-isolate-declaration,
+         -cppcoreguidelines-avoid-c-arrays,
+         -cppcoreguidelines-avoid-magic-numbers,
+         -readability-magic-numbers,
+         -cppcoreguidelines-macro-usage,
+         -cppcoreguidelines-narrowing-conversions,
+         -bugprone-narrowing-conversions,
+         -google-readability-avoid-underscore-in-googletest-name,
+         -cppcoreguidelines-init-variables,
+         -misc-no-recursion,
+         -cppcoreguidelines-avoid-non-const-global-variables,
+         -modernize-avoid-bind
+HeaderFilterRegex: .*
+CheckOptions:
+  - key:           cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor
+    value:         1
+  - key:           modernize-make-unique.IncludeStyle
+    value:         google
+  - key:           modernize-make-shared.IncludeStyle
+    value:         google
+  - key:           readability-implicit-bool-conversion.AllowIntegerConditions
+    value:         1
+  - key:           readability-implicit-bool-conversion.AllowPointerConditions
+    value:         1
+  - key:           bugprone-dangling-handle.HandleClasses
+    value:         std::basic_string_view; nonstd::sv_lite::basic_string_view
+# Permit passing shard pointers by value for sink parameters
+  - key:           performance-unnecessary-copy-initialization.AllowedTypes
+    value:         shared_ptr
+  - key:           performance-unnecessary-value-param.AllowedTypes
+    value:         shared_ptr