diff --git a/.clang-tidy b/.clang-tidy index 6e4edbdfd..4e173e85d 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,47 +1,72 @@ Checks: > - *,-clang-analyzer-alpha.*,-hicpp-*, + *, + -clang-analyzer-*, + -hicpp-*, -clang-diagnostic-ignored-optimization-argument, + -clang-diagnostic-elaborated-enum-base, -altera-*, -abseil-*, -boost-*, + -bugprone-crtp-constructor-accessibility, + -bugprone-derived-method-shadowing-base-method, + -bugprone-easily-swappable-parameters, + -bugprone-implicit-widening-of-multiplication-result, -bugprone-macro-parentheses, -bugprone-narrowing-conversions,-cppcoreguidelines-narrowing-conversions, + -fuchsia-multiple-inheritance,-misc-multiple-inheritance, -llvmlibc-*, -modernize-concat-nested-namespaces, -modernize-loop-convert, + -modernize-return-braced-init-list, + -modernize-use-constraints, + -modernize-use-integer-sign-comparison, -modernize-use-nodiscard, + -modernize-use-ranges, -modernize-use-trailing-return-type, -cppcoreguidelines-avoid-const-or-ref-data-members, -cppcoreguidelines-avoid-do-while, + -cppcoreguidelines-avoid-goto, -hicpp-avoid-goto, -cppcoreguidelines-avoid-magic-numbers, + -cppcoreguidelines-init-variables, -cppcoreguidelines-non-private-member-variables-in-classes, -cppcoreguidelines-macro-usage, -fuchsia-overloaded-operator,-fuchsia-default-arguments*, - hicpp-avoid-goto,hicpp-exception-baseclass,hicpp-multiway-paths-covered, - hicpp-no-assembler,hicpp-signed-bitwise, + -cppcoreguidelines-pro-bounds-avoid-unchecked-container-access, -cppcoreguidelines-pro-bounds-array-to-pointer-decay, -cppcoreguidelines-pro-bounds-constant-array-index, -cppcoreguidelines-pro-bounds-pointer-arithmetic, + -cppcoreguidelines-pro-type-union-access, + -cppcoreguidelines-use-default-member-init,-modernize-use-default-member-init, + -cppcoreguidelines-use-enum-class, -google-readability-casting, -google-readability-todo, -google-runtime-references, -hicpp-signed-bitwise, + -llvm-else-after-return, -llvm-header-guard, -llvm-include-order, + -llvm-use-ranges, -performance-noexcept-move-constructor, -performance-avoid-endl, + -portability-avoid-pragma-once, + -readability-container-contains, + -readability-else-after-return, -readability-identifier-length, -readability-implicit-bool-conversion, + -readability-inconsistent-declaration-parameter-name, + -readability-isolate-declaration, -readability-named-parameter, -readability-magic-numbers, + -readability-math-missing-parentheses, -readability-redundant-access-specifiers, + -readability-redundant-inline-specifier, + -readability-redundant-typename, -misc-non-private-member-variables-in-classes, -misc-confusable-identifiers, -misc-include-cleaner, + -misc-unused-alias-decls, -misc-use-internal-linkage WarningsAsErrors: '' -HeaderFilterRegex: 'modmesh.*' -AnalyzeTemporaryDtors: false FormatStyle: google CheckOptions: - key: cppcoreguidelines-macro-usage.AllowedRegexp diff --git a/.github/actions/setup_linux/action.yml b/.github/actions/setup_linux/action.yml index 84435e182..b0d489eb9 100644 --- a/.github/actions/setup_linux/action.yml +++ b/.github/actions/setup_linux/action.yml @@ -76,12 +76,12 @@ runs: if: ${{ inputs.workflow == 'lint' }} shell: bash run: | - # Install clang-tidy-21 from LLVM repository for full C++23 support + # Install clang-tidy-22 from LLVM repository for full C++23 support wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc - echo "deb http://apt.llvm.org/noble/ llvm-toolchain-noble-21 main" | sudo tee /etc/apt/sources.list.d/llvm.list + echo "deb http://apt.llvm.org/noble/ llvm-toolchain-noble-22 main" | sudo tee /etc/apt/sources.list.d/llvm.list sudo apt-get -qqy update - sudo apt-get -qy install clang-tidy-21 - sudo ln -fs "$(which clang-tidy-21)" "/usr/local/bin/clang-tidy" + sudo apt-get -qy install clang-tidy-22 + sudo ln -fs "$(which clang-tidy-22)" "/usr/local/bin/clang-tidy" - name: Install and configure gcc-14 shell: bash diff --git a/.github/actions/setup_macos/action.yml b/.github/actions/setup_macos/action.yml index aa42f7d29..78c66e12c 100644 --- a/.github/actions/setup_macos/action.yml +++ b/.github/actions/setup_macos/action.yml @@ -24,17 +24,17 @@ runs: # This has been replaced by the 'install qt' section below to manage # qt6 versioning independently from the OS. # brew install llvm@21 qt6 - brew install llvm@21 + brew install llvm@22 # The macos-26 runner ships with Homebrew llvm@20 linked into # /usr/local/bin/ (clang, clang++, clang-format, clang-tidy, etc.). - # Use -sf to overwrite the existing clang-tidy with our llvm@21 + # Use -sf to overwrite the existing clang-tidy with our llvm@22 # version, and remove clang/clang++ so that ccache-action # (create-symlink: true) can create its own symlinks. # clang-format is installed separately via pip (see below) so that # both CI platforms use the version pinned by # CLANG_FORMAT_CI_VERSION in the Makefile. # Ref: https://github.com/actions/runner-images/blob/main/images/macos/macos-26-Readme.md - ln -sf "$(brew --prefix llvm@21)/bin/clang-tidy" "/usr/local/bin/clang-tidy" + ln -sf "$(brew --prefix llvm@22)/bin/clang-tidy" "/usr/local/bin/clang-tidy" rm -f /usr/local/bin/clang /usr/local/bin/clang++ /usr/local/bin/clang-format - name: install qt diff --git a/CMakeLists.txt b/CMakeLists.txt index 4042da482..325d4fc4f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,7 +58,15 @@ find_program( ) if(USE_CLANG_TIDY) if(CLANG_TIDY_EXE) - set(DO_CLANG_TIDY "${CLANG_TIDY_EXE}" "-header-filter=/cpp/.\*/modmesh/.\*" "--extra-arg=-std=c++2b") + set(DO_CLANG_TIDY "${CLANG_TIDY_EXE}" + "-header-filter=/cpp/.\*" + "--extra-arg=-std=c++23" + # FIXME: Remove --allow-no-checks in the future after figuring out + # why the error message "Error: no checks enabled." appears with + # some files, after upgrading to clang-tidy-22. + # Related information (but not what we see in modmesh): + # https://github.com/llvm/llvm-project/issues/192713 + "--allow-no-checks") if(LINT_AS_ERRORS) set(DO_CLANG_TIDY "${DO_CLANG_TIDY}" "-warnings-as-errors=*") endif() diff --git a/cpp/modmesh/CMakeLists.txt b/cpp/modmesh/CMakeLists.txt index 719d3440f..d9c417905 100644 --- a/cpp/modmesh/CMakeLists.txt +++ b/cpp/modmesh/CMakeLists.txt @@ -175,6 +175,7 @@ else () # MSVC ${COMMON_COMPILER_OPTIONS} -Wno-unused-value # for PYBIND11_EXPAND_SIDE_EFFECTS in pybind11.h -Wno-noexcept-type # GCC + -Wno-elaborated-enum-base # for apple accelerate/veclib ) endif () # MSVC diff --git a/cpp/modmesh/base.hpp b/cpp/modmesh/base.hpp index ccd774960..d96cdc5f6 100644 --- a/cpp/modmesh/base.hpp +++ b/cpp/modmesh/base.hpp @@ -41,7 +41,7 @@ #include #include -#if defined(_MSC_VER) +#ifdef _MSC_VER #include typedef SSIZE_T ssize_t; #endif @@ -156,7 +156,7 @@ class [[deprecated("Use std::format instead")]] Formatter // NOLINTNEXTLINE(google-explicit-constructor) operator std::string() const { return m_stream.str(); } - enum ConvertToString + enum ConvertToString : std::uint8_t { to_str }; diff --git a/cpp/modmesh/buffer/BufferBase.hpp b/cpp/modmesh/buffer/BufferBase.hpp index d9e674e35..9cbb0fa22 100644 --- a/cpp/modmesh/buffer/BufferBase.hpp +++ b/cpp/modmesh/buffer/BufferBase.hpp @@ -69,7 +69,7 @@ class BufferBase using size_type = std::size_t; using difference_type = std::ptrdiff_t; - explicit operator bool() const { return bool(m_begin); } + explicit operator bool() const { return static_cast(m_begin); } size_type size() const { return static_cast(this->m_end - this->m_begin); @@ -128,12 +128,14 @@ class BufferBase { } +public: BufferBase(BufferBase const &) = delete; BufferBase(BufferBase &&) = delete; BufferBase & operator=(BufferBase const &) = delete; BufferBase & operator=(BufferBase &&) = delete; ~BufferBase() = default; +protected: void validate_range(size_t it) const { if (it >= size()) diff --git a/cpp/modmesh/buffer/BufferExpander.hpp b/cpp/modmesh/buffer/BufferExpander.hpp index 91c43a79f..102d7ddda 100644 --- a/cpp/modmesh/buffer/BufferExpander.hpp +++ b/cpp/modmesh/buffer/BufferExpander.hpp @@ -78,7 +78,7 @@ class BufferExpander { m_begin = m_concrete_buffer->data(); m_end = m_begin + m_concrete_buffer->size(); - m_end_cap = m_begin + m_concrete_buffer->size(); + m_end_cap = m_begin + m_concrete_buffer->size(); // NOLINT(cppcoreguidelines-prefer-member-initializer) } BufferExpander(std::shared_ptr const & buf, bool clone, ctor_passkey const &) @@ -98,9 +98,9 @@ class BufferExpander { } - BufferExpander(ctor_passkey const &) + explicit BufferExpander(ctor_passkey const &) : BufferBase(nullptr, nullptr) - , m_alignment(0) + , m_alignment(0) // NOLINT(cppcoreguidelines-use-default-member-init,modernize-use-default-member-init) { } @@ -151,7 +151,7 @@ class BufferExpander std::shared_ptr copy_concrete(size_type cap = 0) const; std::shared_ptr const & as_concrete(size_type cap = 0); - bool is_concrete() const { return bool(m_concrete_buffer); } + bool is_concrete() const { return static_cast(m_concrete_buffer); } size_type alignment() const noexcept { return m_alignment; } @@ -178,7 +178,7 @@ class BufferExpander std::free(ptr); } #else - std::free(ptr); + std::free(ptr); // NOLINT(cppcoreguidelines-owning-memory,cppcoreguidelines-no-malloc) #endif } }; @@ -197,13 +197,13 @@ class BufferExpander #ifdef _WIN32 ptr = _aligned_malloc(nbytes, alignment); #else - ptr = std::aligned_alloc(alignment, nbytes); + ptr = std::aligned_alloc(alignment, nbytes); // NOLINT(cppcoreguidelines-owning-memory,cppcoreguidelines-no-malloc) #endif } else { // Use malloc instead of new[] so we can consistently use free in the deleter - ptr = std::malloc(nbytes); + ptr = std::malloc(nbytes); // NOLINT(cppcoreguidelines-owning-memory,cppcoreguidelines-no-malloc) } if (!ptr) { diff --git a/cpp/modmesh/buffer/ConcreteBuffer.hpp b/cpp/modmesh/buffer/ConcreteBuffer.hpp index 2da5df118..8d8bec40e 100644 --- a/cpp/modmesh/buffer/ConcreteBuffer.hpp +++ b/cpp/modmesh/buffer/ConcreteBuffer.hpp @@ -63,17 +63,17 @@ struct ConcreteBufferRemover static void deallocate_memory(int8_t * p, size_t alignment) { - if (alignment > 0) + if (alignment > 0) // NOLINT(bugprone-branch-clone) { #ifdef _WIN32 - _aligned_free(p); + _aligned_free(p); // NOLINT(cppcoreguidelines-owning-memory,cppcoreguidelines-no-malloc) #else - std::free(p); + std::free(p); // NOLINT(cppcoreguidelines-owning-memory,cppcoreguidelines-no-malloc) #endif } else { - std::free(p); + std::free(p); // NOLINT(cppcoreguidelines-owning-memory,cppcoreguidelines-no-malloc) } } @@ -264,7 +264,7 @@ class ConcreteBuffer return *this; } - bool has_remover() const noexcept { return bool(m_data.get_deleter().remover); } + bool has_remover() const noexcept { return static_cast(m_data.get_deleter().remover); } remover_type const & get_remover() const { return *m_data.get_deleter().remover; } remover_type & get_remover() { return *m_data.get_deleter().remover; } @@ -286,14 +286,14 @@ class ConcreteBuffer { validate_size_alignment(nbytes, alignment, "ConcreteBuffer::allocate"); #ifdef _WIN32 - ptr = _aligned_malloc(nbytes, alignment); + ptr = _aligned_malloc(nbytes, alignment); // NOLINT(cppcoreguidelines-owning-memory,cppcoreguidelines-no-malloc) #else - ptr = std::aligned_alloc(alignment, nbytes); + ptr = std::aligned_alloc(alignment, nbytes); // NOLINT(cppcoreguidelines-owning-memory,cppcoreguidelines-no-malloc) #endif } else { - ptr = std::malloc(nbytes); + ptr = std::malloc(nbytes); // NOLINT(cppcoreguidelines-owning-memory,cppcoreguidelines-no-malloc) } if (!ptr) { diff --git a/cpp/modmesh/buffer/SimpleArray.cpp b/cpp/modmesh/buffer/SimpleArray.cpp index 106433bb9..966c9acd8 100644 --- a/cpp/modmesh/buffer/SimpleArray.cpp +++ b/cpp/modmesh/buffer/SimpleArray.cpp @@ -54,7 +54,7 @@ struct DataTypeHasher } }; /* end struct DataTypeHasher */ -// NOLINTNEXTLINE(misc-use-anonymous-namespace, cert-err58-cpp, cppcoreguidelines-avoid-non-const-global-variables, fuchsia-statically-constructed-objects) +// NOLINTNEXTLINE(misc-use-anonymous-namespace, cert-err58-cpp, bugprone-throwing-static-initialization, cppcoreguidelines-avoid-non-const-global-variables, fuchsia-statically-constructed-objects) static std::unordered_map string_data_type_map = { {"bool", DataType::Bool}, {"int8", DataType::Int8}, diff --git a/cpp/modmesh/buffer/SimpleArray.hpp b/cpp/modmesh/buffer/SimpleArray.hpp index cf1f4a7c8..ed619de76 100644 --- a/cpp/modmesh/buffer/SimpleArray.hpp +++ b/cpp/modmesh/buffer/SimpleArray.hpp @@ -45,7 +45,7 @@ #include #include -#if defined(_MSC_VER) +#ifdef _MSC_VER #include typedef SSIZE_T ssize_t; #endif @@ -192,7 +192,7 @@ class SimpleArrayMixinCalculators const size_t ndim = athis->ndim(); small_vector reduce_mask(ndim, false); - for (size_t ax : axis) + for (size_t const ax : axis) { if (ax >= ndim || ax < 0) { @@ -201,7 +201,7 @@ class SimpleArrayMixinCalculators reduce_mask[ax] = true; } - size_t red_count = reduce_mask.count(true); + size_t const red_count = reduce_mask.count(true); if (red_count == 0 || red_count == ndim) { throw std::runtime_error("reduce: no axis to reduce or all axes are reduced"); @@ -253,7 +253,8 @@ class SimpleArrayMixinCalculators } while (red_idx.next_cartesian_product(red_shape)); - element_type mv = std::invoke(red_fn, this, slice, std::forward(red_args)...); + // FIXME: NOLINTNEXTLINE(bugprone-use-after-move) + element_type const mv = std::invoke(red_fn, this, slice, std::forward(red_args)...); result.at(out_idx) = mv; } while (result.next_sidx(out_idx)); @@ -383,7 +384,7 @@ class SimpleArrayMixinCalculators { throw std::runtime_error("SimpleArray::var_op(): ddof must be less than the number of elements"); } - value_type mu = mean_op(sv); + value_type const mu = mean_op(sv); real_type acc = 0; if constexpr (is_complex_v) { @@ -417,7 +418,7 @@ class SimpleArrayMixinCalculators } auto sidx = athis->first_sidx(); - value_type mu = athis->mean(); + value_type const mu = athis->mean(); real_type acc = 0; if constexpr (is_complex_v) { @@ -590,7 +591,7 @@ class SimpleArrayMixinCalculators } else { - size_t size = athis->size(); + size_t const size = athis->size(); for (size_t i = 0; i < size; ++i) { athis->data(i) = athis->data(i) || other.data(i); @@ -688,7 +689,7 @@ class SimpleArrayMixinCalculators } else { - size_t size = athis->size(); + size_t const size = athis->size(); for (size_t i = 0; i < size; ++i) { athis->data(i) = athis->data(i) && other.data(i); @@ -715,7 +716,7 @@ class SimpleArrayMixinCalculators { if (!scalar) { - size_t size = athis->size(); + size_t const size = athis->size(); for (size_t i = 0; i < size; ++i) { athis->data(i) = false; @@ -890,13 +891,13 @@ detail::SimpleArrayMixinCalculators::median_op(small_vector & } else { - value_type v1 = sv.select_kth(n / 2); + value_type const v1 = sv.select_kth(n / 2); if (n % 2 != 0) { return v1; } - value_type v2 = simd::max(sv.begin(), sv.begin() + n / 2); - value_type result = static_cast(v1 + v2) / static_cast(2.0); + value_type const v2 = simd::max(sv.begin(), sv.begin() + n / 2); + value_type const result = static_cast(v1 + v2) / static_cast(2.0); return result; } } @@ -927,19 +928,19 @@ detail::SimpleArrayMixinCalculators::median_freq(small_vector throw std::runtime_error("median_freq(): empty container"); } - uint32_t freq[256] = {}; + uint32_t freq[256] = {}; // NOLINT(cppcoreguidelines-avoid-c-arrays,modernize-avoid-c-arrays) if constexpr (std::is_same_v) { - for (uint8_t v : sv) { ++freq[v]; } + for (uint8_t const v : sv) { ++freq[v]; } } else if constexpr (std::is_same_v) { - for (int8_t v : sv) { ++freq[static_cast(static_cast(v) + 128)]; } + for (int8_t const v : sv) { ++freq[static_cast(static_cast(v) + 128)]; } } else { - for (bool v : sv) { ++freq[v ? 1 : 0]; } + for (bool const v : sv) { ++freq[v ? 1 : 0]; } } int b1, b2; @@ -968,7 +969,7 @@ detail::SimpleArrayMixinCalculators::median_freq(small_vector * This implementation supports 1D x 1D, 1D x 2D, 2D x 1D, and 2D x 2D matrix multiplication. */ template -A SimpleArrayMixinCalculators::matmul(A const & other) const +A SimpleArrayMixinCalculators::matmul(A const & other) const // NOLINT(readability-function-cognitive-complexity) { auto athis = static_cast(this); const size_t this_ndim = athis->ndim(); @@ -1016,8 +1017,8 @@ A SimpleArrayMixinCalculators::matmul(A const & other) const throw std::out_of_range(err); } - bool this_is_1d = (this_ndim == 1); - bool other_is_1d = (other_ndim == 1); + bool const this_is_1d = (this_ndim == 1); + bool const other_is_1d = (other_ndim == 1); // 1D x 1D if (this_is_1d && other_is_1d) @@ -1079,7 +1080,7 @@ A SimpleArrayMixinCalculators::matmul(A const & other) const const size_t n = other.shape(1); check_product_shape(athis, &other, 1, 0); - shape_type result_shape{m, n}; + shape_type const result_shape{m, n}; A result(result_shape); for (size_t i = 0; i < m; ++i) @@ -1164,8 +1165,8 @@ class SimpleArrayMixinSort using value_type = typename internal_types::value_type; - void sort(void); - SimpleArray argsort(void); + void sort(); + SimpleArray argsort(); template A take_along_axis(SimpleArray const & indices); template @@ -1174,7 +1175,7 @@ class SimpleArrayMixinSort }; /* end class SimpleArrayMixinSort */ template -void SimpleArrayMixinSort::sort(void) +void SimpleArrayMixinSort::sort() { auto athis = static_cast(this); if (athis->ndim() != 1) @@ -1188,7 +1189,7 @@ void SimpleArrayMixinSort::sort(void) } template -void indexed_copy(T * dest, T const * data, I const * begin, I const * const end); +void indexed_copy(T * dest, T const * data, I const * begin, I const * const end); // NOLINT(readability-avoid-const-params-in-decls) template T const * check_index_range(SimpleArray const & indices, size_t max_idx); @@ -1255,7 +1256,7 @@ class SimpleArrayMixinMatrix static A eye(ssize_t n) { validate_positive("eye", n); - shape_type shape{static_cast(n), static_cast(n)}; + shape_type const shape{static_cast(n), static_cast(n)}; A result(shape, static_cast(0)); for (ssize_t i = 0; i < n; ++i) @@ -1269,7 +1270,7 @@ class SimpleArrayMixinMatrix static A scaled_eye(ssize_t n, value_type scale) { validate_positive("scaled_eye", n); - shape_type shape{static_cast(n), static_cast(n)}; + shape_type const shape{static_cast(n), static_cast(n)}; A result(shape, static_cast(0)); for (ssize_t i = 0; i < n; ++i) @@ -1623,7 +1624,7 @@ class SimpleArray template SimpleArray & remake(Args &&... args) { - SimpleArray(args...).swap(*this); + SimpleArray(std::forward(args)...).swap(*this); return *this; } @@ -2025,7 +2026,7 @@ class SimpleArray }; /* end class SimpleArray */ template -SimpleArray detail::SimpleArrayMixinSort::argsort(void) +SimpleArray detail::SimpleArrayMixinSort::argsort() { auto athis = static_cast(this); if (athis->ndim() != 1) @@ -2096,11 +2097,11 @@ A detail::SimpleArrayMixinSort::take_along_axis(SimpleArray const & ind src = indices.begin(); A ret(indices.shape()); - T * data = athis->begin(); + T const * data = athis->begin(); T * dst = ret.begin(); while (src < end) { - T * valp = data + static_cast(*src); + T const * valp = data + static_cast(*src); *dst = *valp; ++dst; ++src; @@ -2181,7 +2182,7 @@ A detail::SimpleArrayMixinSort::take_along_axis_simd(SimpleArray const I const * src = indices.begin(); I const * const end = indices.end(); A ret(indices.shape()); - T * data = athis->begin(); + T const * data = athis->begin(); T * dest = ret.begin(); detail::indexed_copy(dest, data, src, end); return ret; @@ -2193,7 +2194,7 @@ using is_simple_array = std::is_same< SimpleArray::value_type>>; template -inline constexpr bool is_simple_array_v = is_simple_array::value; +inline constexpr bool is_simple_array_v = is_simple_array::value; // NOLINT(modernize-type-traits) using SimpleArrayBool = SimpleArray; using SimpleArrayInt8 = SimpleArray; @@ -2212,7 +2213,7 @@ using SimpleArrayComplex128 = SimpleArray>; class DataType { public: - enum enum_type + enum enum_type : std::uint8_t { Undefined, Bool, @@ -2232,16 +2233,16 @@ class DataType DataType() = default; - constexpr DataType(const enum_type datatype) + constexpr DataType(const enum_type datatype) // NOLINT(google-explicit-constructor) : m_data_type(datatype) { } - DataType(const std::string & data_type_string); + DataType(const std::string & data_type_string); // NOLINT(google-explicit-constructor) enum_type type() const { return m_data_type; } - constexpr operator enum_type() const { return m_data_type; } // Allow implicit switch and comparisons. + constexpr operator enum_type() const { return m_data_type; } // Allow implicit switch and comparisons. // NOLINT(google-explicit-constructor) explicit operator bool() const = delete; // Prevent usage: if(datatype) template @@ -2269,16 +2270,18 @@ class SimpleArrayPlex { } - explicit SimpleArrayPlex(const shape_type & shape, const DataType data_type); - explicit SimpleArrayPlex(const shape_type & shape, const std::shared_ptr & buffer, const DataType data_type); - explicit SimpleArrayPlex(const shape_type & shape, const DataType data_type, size_t alignment); + explicit SimpleArrayPlex(const shape_type & shape, DataType data_type); + explicit SimpleArrayPlex(const shape_type & shape, const std::shared_ptr & buffer, DataType data_type); + explicit SimpleArrayPlex(const shape_type & shape, DataType data_type, size_t alignment); template + // FIXME: NOLINTNEXTLINE(google-explicit-constructor) SimpleArrayPlex(const SimpleArray & array) + : m_has_instance_ownership(true) + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) + , m_instance_ptr(reinterpret_cast(new SimpleArray(array))) + , m_data_type(DataType::from()) { - m_data_type = DataType::from(); - m_has_instance_ownership = true; - m_instance_ptr = reinterpret_cast(new SimpleArray(array)); } SimpleArrayPlex(SimpleArrayPlex const & other); diff --git a/cpp/modmesh/buffer/SimpleCollector.hpp b/cpp/modmesh/buffer/SimpleCollector.hpp index 097e9abbf..b9553e706 100644 --- a/cpp/modmesh/buffer/SimpleCollector.hpp +++ b/cpp/modmesh/buffer/SimpleCollector.hpp @@ -58,13 +58,13 @@ class SimpleCollector } // Always (forcefully) clone the input array when it is a const reference - SimpleCollector(SimpleArray const & arr, size_t alignment = 0) + explicit SimpleCollector(SimpleArray const & arr, size_t alignment = 0) : m_expander(BufferExpander::construct(arr.buffer().clone(), /*clone*/ false, alignment)) { } // Allow sharing the buffer when the input array is an lvalue reference - SimpleCollector(SimpleArray & arr, bool clone, size_t alignment = 0) + explicit SimpleCollector(SimpleArray & arr, bool clone, size_t alignment = 0) : m_expander(BufferExpander::construct(arr.buffer().shared_from_this(), clone, alignment)) { } @@ -83,12 +83,12 @@ class SimpleCollector return *this; } - SimpleCollector(SimpleCollector && other) + SimpleCollector(SimpleCollector && other) noexcept : m_expander(std::move(other.m_expander)) { } - SimpleCollector & operator=(SimpleCollector && other) + SimpleCollector & operator=(SimpleCollector && other) noexcept { if (this != &other) { @@ -97,6 +97,8 @@ class SimpleCollector return *this; } + ~SimpleCollector() = default; + size_t size() const { return expander().size() / ITEMSIZE; } size_t capacity() const { return expander().capacity() / ITEMSIZE; } size_t alignment() const { return expander().alignment(); } @@ -135,7 +137,7 @@ class SimpleCollector { size_t const it = size(); push_size(); - (*this)[it] = value; + (*this)[it] = std::move(value); } /* Backdoor */ diff --git a/cpp/modmesh/buffer/pymod/SimpleArrayCaster.hpp b/cpp/modmesh/buffer/pymod/SimpleArrayCaster.hpp index b8e643abb..6bc5117de 100644 --- a/cpp/modmesh/buffer/pymod/SimpleArrayCaster.hpp +++ b/cpp/modmesh/buffer/pymod/SimpleArrayCaster.hpp @@ -66,7 +66,7 @@ namespace detail } \ \ /* Get the SimpleArrayPlex object from the source handle */ \ - modmesh::SimpleArrayPlex arrayplex = src.cast(); \ + modmesh::SimpleArrayPlex arrayplex = src.cast(); /* NOLINT(misc-const-correctness) */ \ \ /* Check if the data type is matched */ \ if (arrayplex.data_type() != modmesh::DataType::DATATYPE) \ @@ -74,13 +74,13 @@ namespace detail return false; \ } \ \ - /* construct the new array from the arrayplex */ \ + /* construct the new array from the arrayplex NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) */ \ const modmesh::SimpleArray##DATATYPE * array_from_arrayplex = reinterpret_cast(arrayplex.instance_ptr()); \ - value = const_cast(array_from_arrayplex); \ + value = const_cast(array_from_arrayplex); /* NOLINT(cppcoreguidelines-pro-type-const-cast) */ \ return true; \ } \ \ - /* Conversion from C++ to Python object */ \ + /* Conversion from C++ to Python object FIXME: NOLINTNEXTLINE(cppcoreguidelines-rvalue-reference-param-not-moved) */ \ static pybind11::handle cast(modmesh::SimpleArray##DATATYPE && src, pybind11::return_value_policy policy, pybind11::handle parent) \ { \ return base::cast(src, policy, parent); \ diff --git a/cpp/modmesh/buffer/pymod/TypeBroadcast.hpp b/cpp/modmesh/buffer/pymod/TypeBroadcast.hpp index e2005c237..6d428790b 100644 --- a/cpp/modmesh/buffer/pymod/TypeBroadcast.hpp +++ b/cpp/modmesh/buffer/pymod/TypeBroadcast.hpp @@ -76,6 +76,7 @@ struct TypeBroadcastImpl if constexpr (valid_conversion) { + // FIXME: NOLINTNEXTLINE(bugprone-signed-char-misuse,cert-str34-c) arr_out.at(offset_out) = static_cast(*ptr_in); } else diff --git a/cpp/modmesh/buffer/pymod/array_common.hpp b/cpp/modmesh/buffer/pymod/array_common.hpp index 284327b09..efe1cc47e 100644 --- a/cpp/modmesh/buffer/pymod/array_common.hpp +++ b/cpp/modmesh/buffer/pymod/array_common.hpp @@ -69,7 +69,7 @@ struct npy_format_descriptor> static void register_dtype(any_container fields) { register_structured_dtype(std::move(fields), - typeid(typename std::remove_cv>::type), + typeid(std::remove_cv_t>), sizeof(modmesh::Complex), &direct_converter); } @@ -77,6 +77,7 @@ struct npy_format_descriptor> private: static PyObject * dtype_ptr() { + // NOLINTNEXTLINE(misc-const-correctness) static PyObject * ptr = get_numpy_internals().get_type_info>(true)->dtype_ptr; return ptr; } @@ -92,7 +93,7 @@ struct npy_format_descriptor> { if (api.PyArray_EquivTypes_(dtype_ptr(), descr.ptr())) { - value = (reinterpret_cast(obj))->obval; + value = (reinterpret_cast(obj))->obval; // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast) return true; } } @@ -119,7 +120,7 @@ struct npy_format_descriptor> static void register_dtype(any_container fields) { register_structured_dtype(std::move(fields), - typeid(typename std::remove_cv>::type), + typeid(std::remove_cv_t>), sizeof(modmesh::Complex), &direct_converter); } @@ -127,6 +128,7 @@ struct npy_format_descriptor> private: static PyObject * dtype_ptr() { + // NOLINTNEXTLINE(misc-const-correctness) static PyObject * ptr = get_numpy_internals().get_type_info>(true)->dtype_ptr; return ptr; } @@ -142,6 +144,7 @@ struct npy_format_descriptor> { if (api.PyArray_EquivTypes_(dtype_ptr(), descr.ptr())) { + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) value = (reinterpret_cast(obj))->obval; return true; } @@ -217,6 +220,7 @@ class ArrayPropertyHelper } } + // FIXME: NOLINTNEXTLINE(readability-function-cognitive-complexity) static void setitem_parser(SimpleArray & arr_out, pybind11::args const & args) { namespace py = pybind11; @@ -228,8 +232,8 @@ class ArrayPropertyHelper // Determine if py_value is a numpy complexx // Reference: https://stackoverflow.com/a/79673025 - py::object builtins = py::module_::import("builtins"); - py::object complex_class = builtins.attr("complex"); + py::object builtins = py::module_::import("builtins"); // NOLINT(misc-const-correctness) + py::object complex_class = builtins.attr("complex"); // NOLINT(misc-const-correctness) const bool is_number = py::isinstance(py_value) || py::isinstance(py_value) || py::isinstance(py_value) || is_complex_v || py::isinstance(py_value, complex_class); // sarr[K] = V diff --git a/cpp/modmesh/buffer/small_vector.hpp b/cpp/modmesh/buffer/small_vector.hpp index fec1ff2f6..e9ca9ab3d 100644 --- a/cpp/modmesh/buffer/small_vector.hpp +++ b/cpp/modmesh/buffer/small_vector.hpp @@ -388,7 +388,7 @@ small_vector::partition(iterator left, iterator right, iterator pivot) { for (int u = 0; u < unroll; ++u) { - bool is_lt = (*it < gap_val); + bool const is_lt = (*it < gap_val); iterator dst = left + lt_count; *gap_pos = std::move(*dst); *dst = std::move(*it); @@ -400,7 +400,7 @@ small_vector::partition(iterator left, iterator right, iterator pivot) for (; it < right; ++it) { - bool is_lt = (*it < gap_val); + bool const is_lt = (*it < gap_val); iterator dst = left + lt_count; *gap_pos = std::move(*dst); *dst = std::move(*it); @@ -420,7 +420,7 @@ typename small_vector::iterator small_vector::quick_select(iterator first, iterator last, size_t k) { MODMESH_PROFILE_SCOPE("small_vector::quick_select()"); - size_t len = last - first; + size_t const len = last - first; if (k >= len) { throw std::out_of_range("quick_select: k out of range"); @@ -431,7 +431,7 @@ small_vector::quick_select(iterator first, iterator last, size_t k) iterator pivot_it = choose_pivot(first, last); iterator store = partition(first, last, pivot_it); - size_t pivot_rank = store - first; + size_t const pivot_rank = store - first; if (pivot_rank == k) { return store; diff --git a/cpp/modmesh/grid.hpp b/cpp/modmesh/grid.hpp index 2488cf3b8..a2b2af4a8 100644 --- a/cpp/modmesh/grid.hpp +++ b/cpp/modmesh/grid.hpp @@ -71,7 +71,7 @@ class AscendantGrid1d : public StaticGridBase<1> AscendantGrid1d & operator=(AscendantGrid1d &&) = default; ~AscendantGrid1d() = default; - explicit operator bool() const { return bool(m_coord); } + explicit operator bool() const { return static_cast(m_coord); } size_t ncoord() const { return m_idmax - m_idmin + 1; } diff --git a/cpp/modmesh/inout/gmsh.hpp b/cpp/modmesh/inout/gmsh.hpp index a08811a16..2edb7efe5 100644 --- a/cpp/modmesh/inout/gmsh.hpp +++ b/cpp/modmesh/inout/gmsh.hpp @@ -66,10 +66,10 @@ class Gmsh Gmsh & operator=(Gmsh const & other) = delete; Gmsh & operator=(Gmsh && other) = delete; - std::shared_ptr to_block(void); + std::shared_ptr to_block(); private: - enum class FormatState + enum class FormatState : uint8_t { BEGIN, META_END, @@ -79,7 +79,7 @@ class Gmsh }; // Check the finite state machine state transition is valid or not to check msh file format is correct - bool is_valid_transition(const std::string s) + bool is_valid_transition(std::string const & s) { if (last_fmt_state == FormatState::BEGIN) { @@ -97,7 +97,7 @@ class Gmsh return false; } - void load_meta(void) + void load_meta() { std::string line; @@ -116,7 +116,7 @@ class Gmsh msh_data_size = std::stoi(tokens[2]); } - if (!line.compare("$EndMeshFormat")) + if (!line.compare("$EndMeshFormat")) // FIXME: NOLINT(readability-string-compare) { last_fmt_state = FormatState::META_END; } @@ -124,19 +124,19 @@ class Gmsh // TODO: PhysicalNames section parsing logic not complete yet, but without PhysicalNames section // modmesh mesh viewer still working, therefore we can finish this later. - void load_physical(void) + void load_physical() { std::string line; while (std::getline(stream, line) && line.find('$') == std::string::npos) {} - if (!line.compare("$EndPhysicalNames")) + if (!line.compare("$EndPhysicalNames")) // FIXME: NOLINT(readability-string-compare) { last_fmt_state = FormatState::PYHSICAL_NAME_END; } } - void load_nodes(void) + void load_nodes() { std::string line; std::getline(stream, line); @@ -153,13 +153,13 @@ class Gmsh m_nds(std::stoul(tokens[0]) - 1, 2) = std::stod(tokens[3]); } - if (!line.compare("$EndNodes")) + if (!line.compare("$EndNodes")) // FIXME: NOLINT(readability-string-compare) { last_fmt_state = FormatState::NODE_END; } } - void load_elements(void) + void load_elements() { std::string line; std::getline(stream, line); @@ -184,6 +184,7 @@ class Gmsh std::vector tag; for (size_t i = 0; i < std::stoul(tokens[2]); ++i) { + // FIXME: NOLINTNEXTLINE(performance-inefficient-vector-operation) tag.push_back(std::stoul(tokens[3 + i])); } @@ -212,7 +213,7 @@ class Gmsh idx++; } - if (!line.compare("$EndElements")) + if (!line.compare("$EndElements")) // FIXME: NOLINT(readability-string-compare) { last_fmt_state = FormatState::ELEMENT_END; } diff --git a/cpp/modmesh/inout/inout_util.hpp b/cpp/modmesh/inout/inout_util.hpp index 369a0e70f..bc017998c 100644 --- a/cpp/modmesh/inout/inout_util.hpp +++ b/cpp/modmesh/inout/inout_util.hpp @@ -42,7 +42,7 @@ namespace inout { std::vector tokenize(const std::string & str, const std::regex & regex_delim); -std::vector tokenize(const std::string & str, const char delim); +std::vector tokenize(const std::string & str, char delim); } // namespace inout diff --git a/cpp/modmesh/inout/plot3d.hpp b/cpp/modmesh/inout/plot3d.hpp index 7db9ea877..93eb2f9e6 100644 --- a/cpp/modmesh/inout/plot3d.hpp +++ b/cpp/modmesh/inout/plot3d.hpp @@ -73,8 +73,8 @@ class Plot3d return blk > 0 ? m_blk_sizes(blk - 1) : 0 + x + y * m_x_shape(blk) + z * m_x_shape(blk) * m_y_shape(blk); } - void parseCoordinates(const uint_type nblocks); - void buildHexahedronElements(const uint_type nblocks); + void parseCoordinates(uint_type nblocks); + void buildHexahedronElements(uint_type nblocks); std::stringstream stream; diff --git a/cpp/modmesh/linalg/factorization.hpp b/cpp/modmesh/linalg/factorization.hpp index f25245711..c4264798b 100644 --- a/cpp/modmesh/linalg/factorization.hpp +++ b/cpp/modmesh/linalg/factorization.hpp @@ -64,7 +64,7 @@ class Llt }; /* end class Llt */ template -auto Llt::forward_substitution(array_type const & l, array_type const & b) -> array_type +Llt::array_type Llt::forward_substitution(array_type const & l, array_type const & b) { if (l.ndim() != 2 || l.shape(0) != l.shape(1)) { @@ -97,9 +97,9 @@ auto Llt::forward_substitution(array_type const & l, array_type const & b) -> throw std::invalid_argument(oss.str()); } - const ssize_t m = static_cast(l.shape(0)); - const ssize_t n = static_cast(b.shape(1)); - small_vector y_shape{static_cast(m), static_cast(n)}; + const auto m = static_cast(l.shape(0)); + const auto n = static_cast(b.shape(1)); + small_vector const y_shape{static_cast(m), static_cast(n)}; array_type y(y_shape); for (ssize_t k = 0; k < n; ++k) { @@ -117,7 +117,7 @@ auto Llt::forward_substitution(array_type const & l, array_type const & b) -> } template -auto Llt::backward_substitution(array_type const & l, array_type const & y) -> array_type +Llt::array_type Llt::backward_substitution(array_type const & l, array_type const & y) { if (l.ndim() != 2 || l.shape(0) != l.shape(1)) { @@ -150,9 +150,9 @@ auto Llt::backward_substitution(array_type const & l, array_type const & y) - throw std::invalid_argument(oss.str()); } - const ssize_t m = static_cast(l.shape(0)); - const ssize_t n = static_cast(y.shape(1)); - small_vector x_shape{static_cast(m), static_cast(n)}; + const auto m = static_cast(l.shape(0)); + const auto n = static_cast(y.shape(1)); + small_vector const x_shape{static_cast(m), static_cast(n)}; array_type x(x_shape); for (ssize_t k = 0; k < n; ++k) { @@ -170,7 +170,7 @@ auto Llt::backward_substitution(array_type const & l, array_type const & y) - } template -auto Llt::factorize(array_type const & a) -> array_type +Llt::array_type Llt::factorize(array_type const & a) { if (a.ndim() != 2 || a.shape(0) != a.shape(1)) { @@ -188,8 +188,8 @@ auto Llt::factorize(array_type const & a) -> array_type throw std::invalid_argument(oss.str()); } - const ssize_t m = static_cast(a.shape(0)); - small_vector shape = {static_cast(m), static_cast(m)}; + const auto m = static_cast(a.shape(0)); + small_vector const shape = {static_cast(m), static_cast(m)}; array_type l(shape, value_type(0)); const real_type eps = std::numeric_limits::epsilon(); for (ssize_t i = 0; i < m; ++i) @@ -203,8 +203,8 @@ auto Llt::factorize(array_type const & a) -> array_type } if (i == j) { - real_type dr = real(a(j, j) - sum); - real_type tol = std::max(1, abs(a(j, j))) * 100 * eps; + real_type const dr = real(a(j, j) - sum); + real_type const tol = std::max(1, abs(a(j, j))) * 100 * eps; if (dr <= tol) { throw std::runtime_error("Llt::factorize: Cholesky failed: SimpleArray not (numerically) SPD."); @@ -221,7 +221,7 @@ auto Llt::factorize(array_type const & a) -> array_type } template -auto Llt::solve(array_type const & a, array_type const & b) -> array_type +Llt::array_type Llt::solve(array_type const & a, array_type const & b) { if (a.ndim() != 2 || a.shape(0) != a.shape(1)) { @@ -251,19 +251,19 @@ auto Llt::solve(array_type const & a, array_type const & b) -> array_type throw std::invalid_argument(oss.str()); } - array_type l = factorize(a); + array_type const l = factorize(a); - bool was_1d = (b.ndim() == 1); + bool const was_1d = (b.ndim() == 1); if (was_1d) { - array_type b_2d = b.reshape(small_vector{b.shape(0), 1}); - array_type y = forward_substitution(l, b_2d); - array_type x = backward_substitution(l, y); + array_type const b_2d = b.reshape(small_vector{b.shape(0), 1}); + array_type const y = forward_substitution(l, b_2d); + array_type const x = backward_substitution(l, y); return x.reshape(small_vector{x.shape(0)}); } else { - array_type y = forward_substitution(l, b); + array_type const y = forward_substitution(l, b); array_type x = backward_substitution(l, y); return x; } diff --git a/cpp/modmesh/linalg/kalman_filter.hpp b/cpp/modmesh/linalg/kalman_filter.hpp index de9d4f3d8..2794a4e36 100644 --- a/cpp/modmesh/linalg/kalman_filter.hpp +++ b/cpp/modmesh/linalg/kalman_filter.hpp @@ -62,8 +62,8 @@ struct KalmanStateInfo KalmanStateInfo(size_t observation_size, size_t state_size) { - small_vector xs_shape{observation_size, state_size}; - small_vector ps_shape{observation_size, state_size, state_size}; + small_vector const xs_shape{observation_size, state_size}; + small_vector const ps_shape{observation_size, state_size, state_size}; prior_states = SimpleArray(xs_shape); prior_states_covariance = SimpleArray(ps_shape); posterior_states = SimpleArray(xs_shape); @@ -132,10 +132,10 @@ class KalmanFilter * @param jitter Numerical stability jitter. */ KalmanFilter( - array_type const & x, - array_type const & f, - array_type const & b, - array_type const & h, + array_type const & x, // FIXME: NOLINT(modernize-pass-by-value) + array_type const & f, // FIXME: NOLINT(modernize-pass-by-value) + array_type const & b, // FIXME: NOLINT(modernize-pass-by-value) + array_type const & h, // FIXME: NOLINT(modernize-pass-by-value) real_type process_noise, real_type measurement_noise, real_type jitter) @@ -226,13 +226,13 @@ class KalmanFilter check_measurement(z); // y <- z - H x (y <- z - m_h @ m_x) - array_type y = innovation(z); + array_type const y = innovation(z); // S <- H P H^H + R + jitter I (s <- m_h @ m_p @ m_h^H + m_r + m_jitter @ I) - array_type s = innovation_covariance(); + array_type const s = innovation_covariance(); // K <- P H^H S^{-1} via LLT solve (k <- m_p @ m_h^H @ s^{-1}) - array_type k = kalman_gain(s); + array_type const k = kalman_gain(s); // x <- x + K y (m_x <- m_x + k @ y) update_state(k, y); @@ -301,6 +301,7 @@ class KalmanFilter }; /* end class KalmanFilter */ template +// FIXME: NOLINTNEXTLINE(readability-function-cognitive-complexity) void KalmanFilter::check_dimensions() { if (m_f.ndim() != 2 || m_f.shape(0) != m_state_size || m_f.shape(1) != m_state_size) @@ -456,7 +457,7 @@ template void KalmanFilter::predict_covariance() { // P <- F P F^H + Q (m_p <- m_f @ m_p @ m_f^H + m_q) - array_type f_h = m_f.hermitian(); + array_type const f_h = m_f.hermitian(); m_p = m_f.matmul(m_p).matmul(f_h).add(m_q); } @@ -517,9 +518,9 @@ template typename KalmanFilter::array_type KalmanFilter::innovation_covariance() { // S <- H P H^H + R + jitter I (s <- m_h @ m_p @ m_h^H + m_r + m_jitter @ I) - array_type h_h = m_h.hermitian(); - array_type hph_h = m_h.matmul(m_p).matmul(h_h); - array_type s = hph_h.add(m_r).add(array_type::scaled_eye(m_measurement_size, static_cast(m_jitter))); + array_type const h_h = m_h.hermitian(); + array_type const hph_h = m_h.matmul(m_p).matmul(h_h); + array_type const s = hph_h.add(m_r).add(array_type::scaled_eye(m_measurement_size, static_cast(m_jitter))); // S <- 0.5(S + S^H) (s <- 0.5(s + s^H)) return s.symmetrize(); @@ -529,8 +530,8 @@ template typename KalmanFilter::array_type KalmanFilter::kalman_gain(array_type const & s) { // K <- P H^H S^{-1} via LLT solve - array_type B = m_h.matmul(m_p); // H@P = B - array_type X = llt_solve(s, B); // S@X = B + array_type const B = m_h.matmul(m_p); // H@P = B + array_type const X = llt_solve(s, B); // S@X = B return X.hermitian(); // K = X^H } @@ -545,12 +546,12 @@ template void KalmanFilter::update_covariance(array_type const & k) { // P <- (I-K H) P (I-K H)^H + K R K^H (m_p <- (I-k@m_h)@m_p@(I-k@m_h)^H + k@m_r@k^H) - array_type kh = k.matmul(m_h); - array_type i_minus_kh = m_i.sub(kh); - array_type i_minus_kh_h = i_minus_kh.hermitian(); - array_type k_h = k.hermitian(); - array_type term1 = i_minus_kh.matmul(m_p).matmul(i_minus_kh_h); - array_type term2 = k.matmul(m_r).matmul(k_h); + array_type const kh = k.matmul(m_h); + array_type const i_minus_kh = m_i.sub(kh); + array_type const i_minus_kh_h = i_minus_kh.hermitian(); + array_type const k_h = k.hermitian(); + array_type const term1 = i_minus_kh.matmul(m_p).matmul(i_minus_kh_h); + array_type const term2 = k.matmul(m_r).matmul(k_h); m_p = term1.add(term2); // P <- 0.5(P + P^H) (m_p <- 0.5(m_p + m_p^H)) @@ -560,8 +561,8 @@ void KalmanFilter::update_covariance(array_type const & k) template KalmanStateInfo KalmanFilter::batch_filter(array_type const & zs) { - size_t z_m = zs.shape(0); - size_t z_n = zs.shape(1); + size_t const z_m = zs.shape(0); + size_t const z_n = zs.shape(1); array_type z(small_vector{z_n}); KalmanStateInfo bfs(z_m, m_state_size); @@ -608,15 +609,15 @@ void KalmanFilter::predict_and_update(array_type const & z, KalmanStateInfo KalmanStateInfo KalmanFilter::batch_filter(array_type const & zs, array_type const & us) { - size_t z_m = zs.shape(0); - size_t z_n = zs.shape(1); + size_t const z_m = zs.shape(0); + size_t const z_n = zs.shape(1); array_type z(small_vector{z_n}); KalmanStateInfo bfs(z_m, m_state_size); array_type u; size_t u_n = 0; - size_t u_m = us.shape(0); + size_t const u_m = us.shape(0); if (u_m != z_m) { throw std::invalid_argument("KalmanFilter::batch_filter: The number of control inputs must match the number of measurements."); diff --git a/cpp/modmesh/linalg/lu_factorization.hpp b/cpp/modmesh/linalg/lu_factorization.hpp index 042a18c50..78c4137f6 100644 --- a/cpp/modmesh/linalg/lu_factorization.hpp +++ b/cpp/modmesh/linalg/lu_factorization.hpp @@ -153,7 +153,7 @@ class Lu }; /* end class Lu */ template -auto Lu::format_shape(array_type const & arr) -> std::string +std::string Lu::format_shape(array_type const & arr) { std::string result = "("; for (size_t i = 0; i < arr.ndim(); ++i) @@ -169,7 +169,7 @@ auto Lu::format_shape(array_type const & arr) -> std::string } template -auto Lu::factorize(array_type const & a) -> std::pair> +std::pair::array_type, std::vector> Lu::factorize(array_type const & a) { if (a.ndim() != 2 || a.shape(0) != a.shape(1)) { @@ -205,7 +205,7 @@ auto Lu::factorize(array_type const & a) -> std::pair max_val) { max_val = val; @@ -254,7 +254,7 @@ auto Lu::factorize(array_type const & a) -> std::pair -auto Lu::forward_substitution(array_type const & lu, std::vector const & piv, array_type const & b) -> array_type +Lu::array_type Lu::forward_substitution(array_type const & lu, std::vector const & piv, array_type const & b) { if (lu.ndim() != 2 || lu.shape(0) != lu.shape(1)) { @@ -271,7 +271,7 @@ auto Lu::forward_substitution(array_type const & lu, std::vector con const auto m = static_cast(lu.shape(0)); const auto ncols = static_cast(b.shape(1)); - small_vector y_shape{static_cast(m), static_cast(ncols)}; + small_vector const y_shape{static_cast(m), static_cast(ncols)}; // Copy b into y so we can apply the permutation in-place. array_type y(y_shape); @@ -310,7 +310,7 @@ auto Lu::forward_substitution(array_type const & lu, std::vector con } template -auto Lu::backward_substitution(array_type const & lu, array_type const & y) -> array_type +Lu::array_type Lu::backward_substitution(array_type const & lu, array_type const & y) { if (lu.ndim() != 2 || lu.shape(0) != lu.shape(1)) { @@ -327,7 +327,7 @@ auto Lu::backward_substitution(array_type const & lu, array_type const & y) - const auto m = static_cast(lu.shape(0)); const auto ncols = static_cast(y.shape(1)); - small_vector x_shape{static_cast(m), static_cast(ncols)}; + small_vector const x_shape{static_cast(m), static_cast(ncols)}; array_type x(x_shape); // Solve Ux = y by backward substitution. U occupies the upper triangle @@ -350,7 +350,7 @@ auto Lu::backward_substitution(array_type const & lu, array_type const & y) - } template -auto Lu::solve(array_type const & a, array_type const & b) -> array_type +Lu::array_type Lu::solve(array_type const & a, array_type const & b) { if (a.ndim() != 2 || a.shape(0) != a.shape(1)) { @@ -396,7 +396,7 @@ auto Lu::solve(array_type const & a, array_type const & b) -> array_type } template -auto Lu::inv(array_type const & a) -> array_type +Lu::array_type Lu::inv(array_type const & a) { if (a.ndim() != 2 || a.shape(0) != a.shape(1)) { diff --git a/cpp/modmesh/linalg/pymod/wrap_factorization.cpp b/cpp/modmesh/linalg/pymod/wrap_factorization.cpp index 62e87beaa..5dd3f6aab 100644 --- a/cpp/modmesh/linalg/pymod/wrap_factorization.cpp +++ b/cpp/modmesh/linalg/pymod/wrap_factorization.cpp @@ -95,7 +95,7 @@ template void add_simple_array_lu_methods(pybind11::module & mod, char const * pyname) { namespace py = pybind11; - py::object cls = mod.attr(pyname); + py::object cls = mod.attr(pyname); // NOLINT(misc-const-correctness) cls.attr("solve") = py::cpp_function( [](SimpleArray const & self, SimpleArray const & b) { return lu_solve(self, b); }, diff --git a/cpp/modmesh/math/Complex.hpp b/cpp/modmesh/math/Complex.hpp index 3812a64f9..34c9c1acd 100644 --- a/cpp/modmesh/math/Complex.hpp +++ b/cpp/modmesh/math/Complex.hpp @@ -53,12 +53,14 @@ struct ComplexImpl { } + // FIXME: NOLINTNEXTLINE(google-explicit-constructor) ComplexImpl(T t) : real_v(t) , imag_v(0.0) { } + // FIXME: NOLINTNEXTLINE(google-explicit-constructor) ComplexImpl(std::complex const & c) : real_v(c.real()) , imag_v(c.imag()) diff --git a/cpp/modmesh/math/math.hpp b/cpp/modmesh/math/math.hpp index a2c80ed80..39b651272 100644 --- a/cpp/modmesh/math/math.hpp +++ b/cpp/modmesh/math/math.hpp @@ -29,6 +29,7 @@ inline constexpr T pow(T base, std::integral_constant /*unused*/) } template +// NOLINTNEXTLINE(google-runtime-float,modernize-use-std-numbers,modernize-avoid-c-style-cast) constexpr T pi_v = std::enable_if_t, T>(3.141592653589793238462643383279502884L); } /* end namespace detail */ diff --git a/cpp/modmesh/mesh/StaticMesh.hpp b/cpp/modmesh/mesh/StaticMesh.hpp index 72835677e..041ad04cd 100644 --- a/cpp/modmesh/mesh/StaticMesh.hpp +++ b/cpp/modmesh/mesh/StaticMesh.hpp @@ -115,7 +115,7 @@ struct CellType : NumberBase uint8_t m_id : 6; uint8_t m_ndim : 2; - uint8_t m_attrs[3] = {0, 0, 0}; + uint8_t m_attrs[3] = {0, 0, 0}; // NOLINT(cppcoreguidelines-avoid-c-arrays,modernize-avoid-c-arrays) }; /* end struct CellType */ @@ -204,7 +204,7 @@ class StaticMeshBC } } - StaticMeshBC(StaticMeshBC && other) + StaticMeshBC(StaticMeshBC && other) // FIXME: NOLINT(bugprone-exception-escape,cppcoreguidelines-noexcept-move-operations) { if (this != &other) { @@ -221,7 +221,7 @@ class StaticMeshBC return *this; } - StaticMeshBC & operator=(StaticMeshBC && other) + StaticMeshBC & operator=(StaticMeshBC && other) // FIXME: NOLINT(bugprone-exception-escape,cppcoreguidelines-noexcept-move-operations) { if (this != &other) { diff --git a/cpp/modmesh/mesh/StaticMesh_interior.cpp b/cpp/modmesh/mesh/StaticMesh_interior.cpp index 74cf41063..137e9be1c 100644 --- a/cpp/modmesh/mesh/StaticMesh_interior.cpp +++ b/cpp/modmesh/mesh/StaticMesh_interior.cpp @@ -365,7 +365,7 @@ struct FaceBuilder // clang-format off return std::accumulate ( - tcltpn.body(), tcltpn.body()+tcltpn.nbody(), size_t(0) + tcltpn.body(), tcltpn.body()+tcltpn.nbody(), static_cast(0) , [](size_t a, uint8_t b){ return a + static_cast(CellType::by_id(b).nface()); } ); // clang-format on diff --git a/cpp/modmesh/mesh/pymod/wrap_StaticGrid.cpp b/cpp/modmesh/mesh/pymod/wrap_StaticGrid.cpp index 93a1f1309..603e3394e 100644 --- a/cpp/modmesh/mesh/pymod/wrap_StaticGrid.cpp +++ b/cpp/modmesh/mesh/pymod/wrap_StaticGrid.cpp @@ -52,7 +52,6 @@ class MODMESH_PYTHON_WRAPPER_VISIBILITY WrapStaticGridBase protected: - // NOLINTNEXTLINE(bugprone-crtp-constructor-accessibility) WrapStaticGridBase(pybind11::module & mod, char const * pyname, char const * pydoc) : base_type(mod, pyname, pydoc) { diff --git a/cpp/modmesh/mesh/pymod/wrap_StaticMesh.cpp b/cpp/modmesh/mesh/pymod/wrap_StaticMesh.cpp index 277429467..68b3d3a25 100644 --- a/cpp/modmesh/mesh/pymod/wrap_StaticMesh.cpp +++ b/cpp/modmesh/mesh/pymod/wrap_StaticMesh.cpp @@ -129,15 +129,15 @@ WrapStaticMesh::WrapStaticMesh(pybind11::module & mod, char const * pyname, char #undef MM_DECL_ARRAY - this->cls().attr("NONCELLTYPE") = uint8_t(CellType::NONCELLTYPE); - this->cls().attr("POINT") = uint8_t(CellType::POINT); - this->cls().attr("LINE") = uint8_t(CellType::LINE); - this->cls().attr("QUADRILATERAL") = uint8_t(CellType::QUADRILATERAL); - this->cls().attr("TRIANGLE") = uint8_t(CellType::TRIANGLE); - this->cls().attr("HEXAHEDRON") = uint8_t(CellType::HEXAHEDRON); - this->cls().attr("TETRAHEDRON") = uint8_t(CellType::TETRAHEDRON); - this->cls().attr("PRISM") = uint8_t(CellType::PRISM); - this->cls().attr("PYRAMID") = uint8_t(CellType::PYRAMID); + this->cls().attr("NONCELLTYPE") = static_cast(CellType::NONCELLTYPE); + this->cls().attr("POINT") = static_cast(CellType::POINT); + this->cls().attr("LINE") = static_cast(CellType::LINE); + this->cls().attr("QUADRILATERAL") = static_cast(CellType::QUADRILATERAL); + this->cls().attr("TRIANGLE") = static_cast(CellType::TRIANGLE); + this->cls().attr("HEXAHEDRON") = static_cast(CellType::HEXAHEDRON); + this->cls().attr("TETRAHEDRON") = static_cast(CellType::TETRAHEDRON); + this->cls().attr("PRISM") = static_cast(CellType::PRISM); + this->cls().attr("PYRAMID") = static_cast(CellType::PYRAMID); } void wrap_StaticMesh(pybind11::module & mod) diff --git a/cpp/modmesh/oasis/oasis_device.cpp b/cpp/modmesh/oasis/oasis_device.cpp index 89a213a8f..5b7e721b2 100644 --- a/cpp/modmesh/oasis/oasis_device.cpp +++ b/cpp/modmesh/oasis/oasis_device.cpp @@ -50,7 +50,7 @@ void OasisDevice::append_unsigned_integer(std::vector & segment, int va while (payload >= 1) { - int first_bit = payload >= 128 ? 1 : 0; + int const first_bit = payload >= 128 ? 1 : 0; segment.push_back((first_bit << 7) | (payload % 128)); payload /= 128; } @@ -68,7 +68,7 @@ void OasisDevice::append_unsigned_integer(std::vector & segment, int va void OasisDevice::append_signed_integer(std::vector & segment, int value) { const int DIR_BIT = value < 0 ? 1 : 0; - int delta_codec = abs(value) << 1 | DIR_BIT; + int const delta_codec = abs(value) << 1 | DIR_BIT; int payload = delta_codec; @@ -79,7 +79,7 @@ void OasisDevice::append_signed_integer(std::vector & segment, int valu while (payload >= 1) { - int first_bit = payload >= 128 ? 1 : 0; + int const first_bit = payload >= 128 ? 1 : 0; segment.push_back((first_bit << 7) | (payload % 128)); payload /= 128; } @@ -165,8 +165,8 @@ std::vector OasisRecordPoly::to_bytes() const for (int i = 0; i < m_vertices.size() - 1; i++) { - std::pair curr_v = m_vertices[i]; - std::pair next_v = m_vertices[i + 1]; + std::pair const curr_v = m_vertices[i]; + std::pair const next_v = m_vertices[i + 1]; // Convert delta value to OASIS signed interegr bytes. OasisDevice::append_signed_integer( @@ -283,7 +283,7 @@ void OasisDevice::append_end_record_byte(std::vector & segment) segment.push_back(0x02); // Write padding. The padding should be 256 bytes. - int padding_length = 254; + int const padding_length = 254; segment.insert(segment.end(), padding_length, 0x00); // Validation-scheme: No validation. diff --git a/cpp/modmesh/onedim/Euler1DCore.hpp b/cpp/modmesh/onedim/Euler1DCore.hpp index 86bbd0ed8..8e11e592a 100644 --- a/cpp/modmesh/onedim/Euler1DCore.hpp +++ b/cpp/modmesh/onedim/Euler1DCore.hpp @@ -282,7 +282,7 @@ inline void Euler1DCore::march_half_so1_alpha(bool odd_plane) MODMESH_PROFILE_SCOPE("Euler1DKernel::march_half_so1_alpha"); const int_type start = BOUND_COUNT - (odd_plane ? 1 : 0); - const int_type stop = static_cast(ncoord() - BOUND_COUNT - (odd_plane ? 0 : 1)); + const auto stop = static_cast(ncoord() - BOUND_COUNT - (odd_plane ? 0 : 1)); // Kernal at xneg solution element. Euler1DKernel kernxn{}; kernxn diff --git a/cpp/modmesh/onedim/pymod/wrap_onedim.cpp b/cpp/modmesh/onedim/pymod/wrap_onedim.cpp index 69b979bd0..26666a37d 100644 --- a/cpp/modmesh/onedim/pymod/wrap_onedim.cpp +++ b/cpp/modmesh/onedim/pymod/wrap_onedim.cpp @@ -72,7 +72,7 @@ class MODMESH_PYTHON_WRAPPER_VISIBILITY WrapEuler1DCore .def_property_readonly_static( "nvar", [](py::handle const &) - { return size_t(wrapped_type::NVAR); }) + { return static_cast(wrapped_type::NVAR); }) .def_property_readonly("time_increment", &wrapped_type::time_increment) .def_property_readonly("ncoord", &wrapped_type::ncoord); diff --git a/cpp/modmesh/python/common.cpp b/cpp/modmesh/python/common.cpp index 29d137270..aa5493221 100644 --- a/cpp/modmesh/python/common.cpp +++ b/cpp/modmesh/python/common.cpp @@ -212,10 +212,10 @@ std::vector Interpreter::get_completions(std::string const & text) std::vector result; try { - pybind11::gil_scoped_acquire gil; + pybind11::gil_scoped_acquire const gil; // NOLINTNEXTLINE(misc-const-correctness) pybind11::object mod_sys = pybind11::module_::import("modmesh.system"); - pybind11::object py_result = mod_sys.attr("get_completions")(text); + pybind11::object const py_result = mod_sys.attr("get_completions")(text); result = py_result.cast>(); } catch (const pybind11::error_already_set & e) @@ -235,11 +235,11 @@ PythonStreamRedirect & PythonStreamRedirect::activate() { auto sys_module = pybind11::module::import("sys"); // Back up old streams. - if (!bool(m_stdout_backup)) + if (!static_cast(m_stdout_backup)) { m_stdout_backup = sys_module.attr("stdout"); } - if (!bool(m_stderr_backup)) + if (!static_cast(m_stderr_backup)) { m_stderr_backup = sys_module.attr("stderr"); } @@ -261,12 +261,12 @@ PythonStreamRedirect & PythonStreamRedirect::activate() PythonStreamRedirect & PythonStreamRedirect::deactivate() { auto sys_module = pybind11::module::import("sys"); - if (bool(m_stdout_backup)) + if (static_cast(m_stdout_backup)) { sys_module.attr("stdout") = m_stdout_backup; m_stdout_backup.release().dec_ref(); } - if (bool(m_stderr_backup)) + if (static_cast(m_stderr_backup)) { sys_module.attr("stderr") = m_stderr_backup; m_stderr_backup.release().dec_ref(); diff --git a/cpp/modmesh/python/common.hpp b/cpp/modmesh/python/common.hpp index f833d1d32..6e2199606 100644 --- a/cpp/modmesh/python/common.hpp +++ b/cpp/modmesh/python/common.hpp @@ -159,7 +159,7 @@ namespace modmesh namespace python { -#if defined(_MSC_VER) +#ifdef _MSC_VER #pragma warning(push) #pragma warning(disable : 4251) // needs to have dll-interface to be used by clients of class #pragma warning(disable : 4275) // non dll-interface struct used as base for dll-interface struct @@ -189,11 +189,12 @@ ConcreteBufferNdarrayRemover : ConcreteBuffer::remover_type pybind11::array ndarray; }; /* end struct ConcreteBufferNdarrayRemover */ -#if defined(_MSC_VER) +#ifdef _MSC_VER #pragma warning(pop) #endif template +// FIXME: NOLINTNEXTLINE(cppcoreguidelines-missing-std-forward) std::enable_if_t, pybind11::array> to_ndarray(S && sarr) { namespace py = pybind11; @@ -226,7 +227,7 @@ static SimpleArray makeSimpleArray(pybind11::array_t & ndarr) return SimpleArray(shape, buffer); } -#if defined(_MSC_VER) +#ifdef _MSC_VER #pragma warning(push) #pragma warning(disable : 4251) // needs to have dll-interface to be used by clients of class #endif @@ -266,7 +267,7 @@ WrapBase >; using class_ = typename std::conditional_t < - std::is_same< Wrapped, WrappedBase >::value + std::is_same_v< Wrapped, WrappedBase > , pybind11::class_< wrapped_type, holder_type > , pybind11::class_< wrapped_type, wrapped_base_type, holder_type > >; @@ -331,13 +332,14 @@ WrapBase } template + // FIXME: NOLINTNEXTLINE(cppcoreguidelines-missing-std-forward) wrapper_type & expose_SimpleArray(char const * name, Func && f) { namespace py = pybind11; using array_reference = typename std::invoke_result_t; - static_assert(std::is_reference::value, "this_array_reference is not a reference"); - static_assert(!std::is_const::value, "this_array_reference cannot be const"); + static_assert(std::is_reference_v, "this_array_reference is not a reference"); + static_assert(!std::is_const_v, "this_array_reference cannot be const"); using array_type = typename std::remove_reference_t; (*this) @@ -364,13 +366,14 @@ WrapBase } template + // FIXME: NOLINTNEXTLINE(cppcoreguidelines-missing-std-forward) wrapper_type & expose_SimpleArrayAsNdarray(char const * name, Func && f) { namespace py = pybind11; using array_reference = typename std::invoke_result_t; - static_assert(std::is_reference::value, "this_array_reference is not a reference"); - static_assert(!std::is_const::value, "this_array_reference cannot be const"); + static_assert(std::is_reference_v, "this_array_reference is not a reference"); + static_assert(!std::is_const_v, "this_array_reference cannot be const"); using array_type = typename std::remove_reference_t; (*this) @@ -411,7 +414,7 @@ WrapBase class_ m_cls; }; /* end class WrapBase */ -#if defined(_MSC_VER) +#ifdef _MSC_VER #pragma warning(pop) #endif @@ -515,7 +518,7 @@ class PythonStreamRedirect public: - PythonStreamRedirect(bool enabled) + explicit PythonStreamRedirect(bool enabled) { set_enabled(enabled); } @@ -529,13 +532,14 @@ class PythonStreamRedirect return *this; } + // FIXME: NOLINTNEXTLINE(readability-convert-member-functions-to-static) bool is_enabled() const { return Toggle::instance().fixed().get_python_redirect(); } bool is_disabled() const { return !is_enabled(); } PythonStreamRedirect & activate(); PythonStreamRedirect & deactivate(); - bool is_activated() const { return bool(m_stdout_backup) || bool(m_stderr_backup); } + bool is_activated() const { return static_cast(m_stdout_backup) || static_cast(m_stderr_backup); } bool is_deactivated() const { return !is_activated(); } private: diff --git a/cpp/modmesh/serialization/SerializableItem.hpp b/cpp/modmesh/serialization/SerializableItem.hpp index e487a6b47..b18b68ea8 100644 --- a/cpp/modmesh/serialization/SerializableItem.hpp +++ b/cpp/modmesh/serialization/SerializableItem.hpp @@ -41,11 +41,13 @@ namespace modmesh { +// FIXME: NOLINTNEXTLINE(cppcoreguidelines-special-member-functions) class SerializableItem { public: virtual std::string to_json() const = 0; virtual void from_json(const std::string & json) = 0; + virtual ~SerializableItem() = default; // TODO: Add more serialization methods, e.g., to/from binary, to/from YAML. }; /* end class SerializableItem */ @@ -60,7 +62,7 @@ std::string escape_string(std::string_view str_view); std::string trim_string(const std::string & str); /// State of the JSON parser. -enum class JsonState +enum class JsonState : uint8_t { Start, ObjectKey, @@ -71,7 +73,7 @@ enum class JsonState }; /* end enum class JsonState */ /// Type of JSON token. -enum class JsonType +enum class JsonType : uint8_t { Object, Array, @@ -93,14 +95,17 @@ struct JsonNode JsonType type; JsonValue value; + // FIXME: NOLINTNEXTLINE(misc-no-recursion) JsonNode(JsonType type, const std::string & expression) : type(type) { + // FIXME: NOLINTNEXTLINE(misc-no-recursion) parse(expression); } private: + // FIXME: NOLINTNEXTLINE(misc-no-recursion) void parse(const std::string & expression) { if (type == JsonType::Object) @@ -117,8 +122,10 @@ struct JsonNode } } + // FIXME: NOLINTNEXTLINE(misc-no-recursion) static JsonMap parse_object(const std::string & json); + // FIXME: NOLINTNEXTLINE(misc-no-recursion) static JsonArray parse_array(const std::string & json); }; /* end struct JsonNode */ @@ -141,7 +148,7 @@ class JsonHelper }; /* end class JsonHelper */ template -std::string JsonHelper::to_json_string(const T & value) +std::string JsonHelper::to_json_string(const T & value) // FIXME: NOLINT(misc-no-recursion) { if constexpr (std::is_base_of_v) { @@ -177,7 +184,7 @@ std::string JsonHelper::to_json_string(const T & value) std::vector keys; for (const auto & kv : value) { - keys.push_back(kv.first); + keys.push_back(kv.first); // FIXME: NOLINT(performance-inefficient-vector-operation) } std::sort(keys.begin(), keys.end()); // TODO: the sorting may not be necessary. This is more for the testing purpose. @@ -200,6 +207,7 @@ std::string JsonHelper::to_json_string(const T & value) } template +// FIXME: NOLINTNEXTLINE(readability-function-cognitive-complexity,misc-no-recursion) void JsonHelper::from_json_string(const std::unique_ptr & node, T & value) { if (node->type == detail::JsonType::Null) @@ -240,7 +248,7 @@ void JsonHelper::from_json_string(const std::unique_ptr & node, T & va } if (std::get(node->value) == "false") { - value = false; + value = false; // NOLINT(readability-simplify-boolean-expr) } else { @@ -285,6 +293,7 @@ void JsonHelper::from_json_string(const std::unique_ptr & node, T & va } template +// NOLINTNEXTLINE(misc-no-recursion) void JsonHelper::from_json_string(const std::unique_ptr & node, std::vector & vec) { if (node->type == JsonType::Null) @@ -318,6 +327,7 @@ void JsonHelper::from_json_string(const std::unique_ptr & node, std::v /// The access modifier will be changed to private after the macro. #define MM_DECL_SERIALIZABLE(...) \ public: \ + /* FIXME: NOLINTNEXTLINE(misc-no-recursion) */ \ std::string to_json() const override \ { \ std::ostringstream oss; \ @@ -355,6 +365,7 @@ private: friend class detail::JsonHelper; \ \ /* for the nested object, we already parsed the json */ \ + /* FIXME: NOLINTNEXTLINE(misc-no-recursion) */ \ void from_json(const detail::JsonMap & json_map) \ { \ auto register_member = [&](const char * name, auto && value) \ diff --git a/cpp/modmesh/simd/neon/neon.hpp b/cpp/modmesh/simd/neon/neon.hpp index 9680dfb88..bd37d830d 100644 --- a/cpp/modmesh/simd/neon/neon.hpp +++ b/cpp/modmesh/simd/neon/neon.hpp @@ -32,7 +32,7 @@ #include #include -#if defined(__aarch64__) +#ifdef __aarch64__ #include #endif /* defined(__aarch64__) */ @@ -52,7 +52,7 @@ namespace detail template bool is_aligned(T const * pointer, size_t alignment) { - return (reinterpret_cast(pointer) % alignment) == 0; + return (reinterpret_cast(pointer) % alignment) == 0; // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast) } template @@ -60,6 +60,7 @@ void check_alignment(T const * pointer, size_t required_alignment, const char * { if (!is_aligned(pointer, required_alignment)) { + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,modernize-use-std-print,cert-err33-c) std::fprintf(stderr, "Warning: %s pointer %p is not aligned to %zu bytes. " "SIMD performance may be degraded.\n", @@ -76,7 +77,7 @@ inline constexpr size_t get_recommended_alignment() #if defined(__aarch64__) || defined(__arm__) return 16; // TODO: The non-NEON conditional should be factored out elsewhere in the future. -#elif defined(__AVX512F__) +#elifdef __AVX512F__ return 64; #elif defined(__AVX__) || defined(__AVX2__) return 32; @@ -89,7 +90,7 @@ inline constexpr size_t get_recommended_alignment() } /* end namespace detail */ -#if defined(__aarch64__) +#ifdef __aarch64__ template > * = nullptr> const T * check_between(T const * start, T const * end, T const & min_val, T const & max_val) { @@ -108,24 +109,24 @@ const T * check_between(T const * start, T const * end, T const & min_val, T con detail::check_alignment(start, alignment, "check_between start"); #endif - vec_t max_vec = vdupq(max_val); - vec_t min_vec = vdupq(min_val); + vec_t const max_vec = vdupq(max_val); + vec_t const min_vec = vdupq(min_val); vec_t data_vec = {}; cmpvec_t cmp_vec = {}; - T const * ret = NULL; + T const * ret = nullptr; T const * ptr = start; for (; ptr <= end - N_lane; ptr += N_lane) { data_vec = vld1q(ptr); - cmp_vec = (cmpvec_t)vcgeq(data_vec, max_vec); + cmp_vec = (cmpvec_t)vcgeq(data_vec, max_vec); // NOLINT(modernize-avoid-c-style-cast) if (vgetq<0>(cmp_vec) || vgetq<1>(cmp_vec)) { goto OUT_OF_RANGE; } - cmp_vec = (cmpvec_t)vcltq(data_vec, min_vec); + cmp_vec = (cmpvec_t)vcltq(data_vec, min_vec); // NOLINT(modernize-avoid-c-style-cast) if (vgetq<0>(cmp_vec) || vgetq<1>(cmp_vec)) { @@ -141,8 +142,8 @@ const T * check_between(T const * start, T const * end, T const & min_val, T con return ret; OUT_OF_RANGE: - T cmp_val[N_lane] = {}; - T * cmp = cmp_val; + T cmp_val[N_lane] = {}; // NOLINT(cppcoreguidelines-avoid-c-arrays,modernize-avoid-c-arrays) + T const * cmp = cmp_val; vst1q(cmp_val, cmp_vec); for (size_t i = 0; i < N_lane; ++i, ++cmp) @@ -158,7 +159,7 @@ const T * check_between(T const * start, T const * end, T const & min_val, T con template void add(T * dest, T const * dest_end, T const * src1, T const * src2) { - if constexpr (!(type::has_vectype)) + if constexpr (!type::has_vectype) { return generic::add(dest, dest_end, src1, src2); } @@ -195,7 +196,7 @@ void add(T * dest, T const * dest_end, T const * src1, T const * src2) template void sub(T * dest, T const * dest_end, T const * src1, T const * src2) { - if constexpr (!(type::has_vectype)) + if constexpr (!type::has_vectype) { return generic::sub(dest, dest_end, src1, src2); } @@ -232,7 +233,7 @@ void sub(T * dest, T const * dest_end, T const * src1, T const * src2) template void mul(T * dest, T const * dest_end, T const * src1, T const * src2) { - if constexpr (!((type::vector_lane > 2))) + if constexpr (!(type::vector_lane > 2)) { return generic::mul(dest, dest_end, src1, src2); } @@ -269,7 +270,7 @@ void mul(T * dest, T const * dest_end, T const * src1, T const * src2) template void div(T * dest, T const * dest_end, T const * src1, T const * src2) { - if constexpr (!(std::is_floating_point_v)) + if constexpr (!std::is_floating_point_v) { return generic::div(dest, dest_end, src1, src2); } diff --git a/cpp/modmesh/simd/neon/neon_alias.hpp b/cpp/modmesh/simd/neon/neon_alias.hpp index db7be7348..cef3f5a0b 100644 --- a/cpp/modmesh/simd/neon/neon_alias.hpp +++ b/cpp/modmesh/simd/neon/neon_alias.hpp @@ -28,7 +28,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#if defined(__aarch64__) +#ifdef __aarch64__ #include #include @@ -158,12 +158,12 @@ DECL_MM_IMPL_VST1Q(64) inline static void vst1q(float * ptr, type::vector_t vec) { - return vst1q_f32(ptr, vec); + vst1q_f32(ptr, vec); } inline static void vst1q(double * ptr, type::vector_t vec) { - return vst1q_f64(ptr, vec); + vst1q_f64(ptr, vec); } #define DECL_MM_IMPL_VCGEQ(N) \ diff --git a/cpp/modmesh/simd/neon/neon_type.hpp b/cpp/modmesh/simd/neon/neon_type.hpp index aca38ed53..1f3bdc8a6 100644 --- a/cpp/modmesh/simd/neon/neon_type.hpp +++ b/cpp/modmesh/simd/neon/neon_type.hpp @@ -28,7 +28,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#if defined(__aarch64__) +#ifdef __aarch64__ #include #include diff --git a/cpp/modmesh/simd/simd.hpp b/cpp/modmesh/simd/simd.hpp index e00b14e48..08318276b 100644 --- a/cpp/modmesh/simd/simd.hpp +++ b/cpp/modmesh/simd/simd.hpp @@ -57,7 +57,7 @@ const T * check_between(T const * start, T const * end, T const & min_val, T con template void add(T * dest, T const * dest_end, T const * src1, T const * src2) { - using namespace detail; + using namespace detail; // FIXME: NOLINT(google-build-using-namespace) switch (detect_simd()) { case SIMD_NEON: @@ -72,7 +72,7 @@ void add(T * dest, T const * dest_end, T const * src1, T const * src2) template void sub(T * dest, T const * dest_end, T const * src1, T const * src2) { - using namespace detail; + using namespace detail; // FIXME: NOLINT(google-build-using-namespace) switch (detect_simd()) { case SIMD_NEON: @@ -87,7 +87,7 @@ void sub(T * dest, T const * dest_end, T const * src1, T const * src2) template void mul(T * dest, T const * dest_end, T const * src1, T const * src2) { - using namespace detail; + using namespace detail; // FIXME: NOLINT(google-build-using-namespace) switch (detect_simd()) { case SIMD_NEON: @@ -102,7 +102,7 @@ void mul(T * dest, T const * dest_end, T const * src1, T const * src2) template void div(T * dest, T const * dest_end, T const * src1, T const * src2) { - using namespace detail; + using namespace detail; // FIXME: NOLINT(google-build-using-namespace) switch (detect_simd()) { case SIMD_NEON: diff --git a/cpp/modmesh/simd/simd_support.cpp b/cpp/modmesh/simd/simd_support.cpp index 87968262d..bf24468a2 100644 --- a/cpp/modmesh/simd/simd_support.cpp +++ b/cpp/modmesh/simd/simd_support.cpp @@ -33,10 +33,10 @@ #if defined(__aarch64__) || defined(__arm__) #include #endif -#elif defined(_WIN32) +#elifdef _WIN32 #include #include -#elif defined(__APPLE__) +#elifdef __APPLE__ #include #endif @@ -68,14 +68,14 @@ SimdFeature detect_simd() CurrentFeature = SIMD_NEON; } #endif /* HWCAP_NEON */ -#elif defined(__APPLE__) +#elifdef __APPLE__ int neon_supported = 0; size_t size = sizeof(neon_supported); if (sysctlbyname("hw.optional.neon", &neon_supported, &size, nullptr, 0) == 0 && neon_supported) { CurrentFeature = SIMD_NEON; } -#elif defined(_WIN32) +#elifdef _WIN32 if (IsProcessorFeaturePresent(PF_ARM_NEON_INSTRUCTIONS_AVAILABLE)) { CurrentFeature = SIMD_NEON; diff --git a/cpp/modmesh/simd/simd_support.hpp b/cpp/modmesh/simd/simd_support.hpp index 4336b881d..a710b898f 100644 --- a/cpp/modmesh/simd/simd_support.hpp +++ b/cpp/modmesh/simd/simd_support.hpp @@ -28,6 +28,8 @@ * POSSIBILITY OF SUCH DAMAGE. */ +#include + namespace modmesh { @@ -37,7 +39,7 @@ namespace simd namespace detail { -enum SimdFeature +enum SimdFeature : std::uint8_t { SIMD_NONE = 0, SIMD_NEON, @@ -53,7 +55,7 @@ enum SimdFeature SIMD_UNKNOWN }; -SimdFeature detect_simd(void); +SimdFeature detect_simd(); } /* namespace detail */ diff --git a/cpp/modmesh/spacetime/core.hpp b/cpp/modmesh/spacetime/core.hpp index bc40d78bf..031afdbc8 100644 --- a/cpp/modmesh/spacetime/core.hpp +++ b/cpp/modmesh/spacetime/core.hpp @@ -498,7 +498,7 @@ class Selm value_type tn(size_t iv) const { return field().kernel().calc_tn(*this, iv); } value_type tp(size_t iv) const { return field().kernel().calc_tp(*this, iv); } value_type so0p(size_t iv) const { return field().kernel().calc_so0p(*this, iv); } - void update_cfl() { return field().kernel().update_cfl(*this); } + void update_cfl() { field().kernel().update_cfl(*this); } }; /* end class Selm */ @@ -947,7 +947,7 @@ template inline void SolverBase::march_half_so0(bool odd_plane) { const int_type start = odd_plane ? -1 : 0; - const int_type stop = static_cast(grid().ncelm()); + const auto stop = static_cast(grid().ncelm()); for (int_type ic = start; ic < stop; ++ic) { auto ce = celm(ic, odd_plane); @@ -959,7 +959,7 @@ template inline void SolverBase::update_cfl(bool odd_plane) { const int_type start = odd_plane ? -1 : 0; - const int_type stop = static_cast(grid().nselm()); + const auto stop = static_cast(grid().nselm()); for (int_type ic = start; ic < stop; ++ic) { selm(ic, odd_plane).update_cfl(); @@ -971,7 +971,7 @@ template inline void SolverBase::march_half_so1_alpha(bool odd_plane) { const int_type start = odd_plane ? -1 : 0; - const int_type stop = static_cast(grid().ncelm()); + const auto stop = static_cast(grid().ncelm()); for (int_type ic = start; ic < stop; ++ic) { auto ce = celm(ic, odd_plane); diff --git a/cpp/modmesh/toggle/RadixTree.hpp b/cpp/modmesh/toggle/RadixTree.hpp index 0d4374c4e..97ebd8a53 100644 --- a/cpp/modmesh/toggle/RadixTree.hpp +++ b/cpp/modmesh/toggle/RadixTree.hpp @@ -54,9 +54,9 @@ class RadixTreeNode static_assert(std::is_integral_v && std::is_signed_v, "signed integral required"); - RadixTreeNode(std::string const & name, key_type key) + RadixTreeNode(std::string name, key_type key) : m_key(key) - , m_name(name) + , m_name(std::move(name)) , m_prev(nullptr) { } @@ -136,7 +136,7 @@ class RadixTree T & entry(const std::string & name) { - key_type id = get_id(name); + key_type const id = get_id(name); RadixTreeNode * child = m_current_node->get_child(id); @@ -183,8 +183,8 @@ class RadixTree RadixTreeNode * get_root() const { return m_root.get(); } RadixTreeNode * get_current_node() const { return m_current_node; } - const key_type get_unique_node() const { return m_unique_id; } - const key_type get_stable_unique_node() const { return m_stable_unique_id; } + key_type get_unique_node() const { return m_unique_id; } + key_type get_stable_unique_node() const { return m_stable_unique_id; } const std::unordered_map & get_stable_id_map() const { return m_stable_id_map; } const std::unordered_map & get_id_map() const { return m_id_map; } @@ -289,12 +289,12 @@ class CallProfiler const RadixTree & radix_tree() const { return m_radix_tree; } private: - void print_profiling_result(const RadixTreeNode & node, const int depth, std::ostream & outstream) const; + void print_profiling_result(const RadixTreeNode & node, int depth, std::ostream & outstream) const; static void print_statistics(const RadixTreeNode & node, std::ostream & outstream); void update_pending_nodes() { - for (auto & node : m_pending_nodes) + for (auto const & node : m_pending_nodes) { node->data().update_stable_items(); } diff --git a/cpp/modmesh/toggle/SerializableProfiler.hpp b/cpp/modmesh/toggle/SerializableProfiler.hpp index 952d80513..bdccaf3ea 100644 --- a/cpp/modmesh/toggle/SerializableProfiler.hpp +++ b/cpp/modmesh/toggle/SerializableProfiler.hpp @@ -34,7 +34,8 @@ namespace modmesh { -class SerializableRadixTreeNode : SerializableItem +// NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init) +class SerializableRadixTreeNode : public SerializableItem { public: @@ -42,13 +43,16 @@ class SerializableRadixTreeNode : SerializableItem using child_list_type = std::vector; using key_type = typename RadixTree::key_type; + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init) SerializableRadixTreeNode() = default; SerializableRadixTreeNode(SerializableRadixTreeNode const &) = default; SerializableRadixTreeNode(SerializableRadixTreeNode &&) = default; SerializableRadixTreeNode & operator=(SerializableRadixTreeNode const &) = default; SerializableRadixTreeNode & operator=(SerializableRadixTreeNode &&) = default; - ~SerializableRadixTreeNode() = default; - SerializableRadixTreeNode(const RadixTreeNode * node) + ~SerializableRadixTreeNode() override = default; + + // FIXME: NOLINTNEXTLINE(misc-no-recursion) + explicit SerializableRadixTreeNode(const RadixTreeNode * node) : m_key(node->key()) , m_name(node->name()) , m_total_time(node->data().stable_total_time) @@ -58,11 +62,12 @@ class SerializableRadixTreeNode : SerializableItem { if (child->data().stable_call_count > 0) { - m_children.push_back(SerializableRadixTreeNode(child.get())); + m_children.push_back(SerializableRadixTreeNode(child.get())); // FIXME: NOLINT(modernize-use-emplace) } } } + // NOLINTNEXTLINE(misc-no-recursion) MM_DECL_SERIALIZABLE( register_member("key", m_key); register_member("name", m_name); @@ -84,7 +89,8 @@ class SerializableRadixTreeNode : SerializableItem child_list_type m_children; }; /* end class SerializableRadixTreeNode */ -class SerializableRadixTree : SerializableItem +// FIXME: NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init) +class SerializableRadixTree : public SerializableItem { public: @@ -95,8 +101,9 @@ class SerializableRadixTree : SerializableItem SerializableRadixTree(SerializableRadixTree &&) = default; SerializableRadixTree & operator=(SerializableRadixTree const &) = default; SerializableRadixTree & operator=(SerializableRadixTree &&) = default; - ~SerializableRadixTree() = default; - SerializableRadixTree(const RadixTree & radix_tree) + ~SerializableRadixTree() override = default; + + explicit SerializableRadixTree(const RadixTree & radix_tree) : m_root(radix_tree.get_root()) , m_id_map(radix_tree.get_stable_id_map()) , m_unique_id(radix_tree.get_stable_unique_node()) @@ -124,9 +131,9 @@ class CallProfilerSerializer // It returns the json format of the CallProfiler. static std::string serialize(const CallProfiler & profiler) { - auto radix_tree_curent_node = profiler.radix_tree().get_current_node(); - auto radix_tree_root = profiler.radix_tree().get_root(); - SerializableRadixTree serializable_radix_tree(profiler.radix_tree()); + auto * radix_tree_curent_node = profiler.radix_tree().get_current_node(); + auto * radix_tree_root = profiler.radix_tree().get_root(); + SerializableRadixTree const serializable_radix_tree(profiler.radix_tree()); return serializable_radix_tree.to_json(); } diff --git a/cpp/modmesh/toggle/profile.hpp b/cpp/modmesh/toggle/profile.hpp index c978c1e8e..fac708c99 100644 --- a/cpp/modmesh/toggle/profile.hpp +++ b/cpp/modmesh/toggle/profile.hpp @@ -86,7 +86,7 @@ class StopWatch */ static constexpr double resolution() { - return double(clock_type::period::num) / double(clock_type::period::den); + return static_cast(clock_type::period::num) / static_cast(clock_type::period::den); } private: diff --git a/cpp/modmesh/toggle/pymod/toggle_pymod.hpp b/cpp/modmesh/toggle/pymod/toggle_pymod.hpp index ca812a959..68d95e9e1 100644 --- a/cpp/modmesh/toggle/pymod/toggle_pymod.hpp +++ b/cpp/modmesh/toggle/pymod/toggle_pymod.hpp @@ -42,8 +42,6 @@ namespace python void initialize_toggle(pybind11::module & mod); void wrap_profile(pybind11::module & mod); -void wrap_StaticGrid(pybind11::module & mod); -void wrap_StaticMesh(pybind11::module & mod); void wrap_Toggle(pybind11::module & mod); } /* end namespace python */ diff --git a/cpp/modmesh/toggle/toggle.cpp b/cpp/modmesh/toggle/toggle.cpp index e805d65e7..aeb358ade 100644 --- a/cpp/modmesh/toggle/toggle.cpp +++ b/cpp/modmesh/toggle/toggle.cpp @@ -68,7 +68,7 @@ SolidToggle::SolidToggle() { } -// NOLINTNEXTLINE(fuchsia-statically-constructed-objects,readability-redundant-string-init,cert-err58-cpp) +// NOLINTNEXTLINE(bugprone-throwing-static-initialization,fuchsia-statically-constructed-objects,readability-redundant-string-init,cert-err58-cpp) std::string const DynamicToggleTable::sentinel_string = ""; /* The macro gives debuggers a hard time. Manually expand it if you need to @@ -152,7 +152,7 @@ void DynamicToggleTable::add_subkey(std::string const & key) auto it = m_key2index.find(key); if (it == m_key2index.end()) { - DynamicToggleIndex const index{0, DynamicToggleIndex::TYPE_SUBKEY}; + DynamicToggleIndex const index{.index = 0, .type = DynamicToggleIndex::TYPE_SUBKEY}; m_key2index.insert({key, index}); } } diff --git a/cpp/modmesh/toggle/toggle.hpp b/cpp/modmesh/toggle/toggle.hpp index f8eeadc2f..24880e7a7 100644 --- a/cpp/modmesh/toggle/toggle.hpp +++ b/cpp/modmesh/toggle/toggle.hpp @@ -32,7 +32,6 @@ #include #include #include -#include #include #include @@ -59,7 +58,7 @@ struct DynamicToggleIndex TYPE_SUBKEY }; - operator bool() const { return type != TYPE_NONE; } + explicit operator bool() const { return type != TYPE_NONE; } bool is_bool() const { return type == TYPE_BOOL; } bool is_int8() const { return type == TYPE_INT8; } bool is_int16() const { return type == TYPE_INT16; } @@ -133,7 +132,7 @@ class DynamicToggleTable using keymap_type = std::unordered_map; - static std::string const sentinel_string; + static std::string const sentinel_string; // FIXME: NOLINT(readability-redundant-string-init) bool get_bool(std::string const & key) const; void set_bool(std::string const & key, bool value); @@ -159,7 +158,7 @@ class DynamicToggleTable DynamicToggleIndex get_index(std::string const & key) const { auto it = m_key2index.find(key); - return (it != m_key2index.end()) ? it->second : DynamicToggleIndex{0, DynamicToggleIndex::TYPE_NONE}; + return (it != m_key2index.end()) ? it->second : DynamicToggleIndex{.index = 0, .type = DynamicToggleIndex::TYPE_NONE}; } std::vector keys() const; void clear(); @@ -268,7 +267,7 @@ class Toggle static Toggle & instance(); - Toggle * clone() const { return new Toggle(*this); } + Toggle * clone() const { return new Toggle(*this); /* NOLINT(cppcoreguidelines-owning-memory) */ } ~Toggle() = default; diff --git a/cpp/modmesh/transform/fourier.hpp b/cpp/modmesh/transform/fourier.hpp index 289ecf9ea..9c12d22d1 100644 --- a/cpp/modmesh/transform/fourier.hpp +++ b/cpp/modmesh/transform/fourier.hpp @@ -9,7 +9,7 @@ namespace modmesh namespace detail { -size_t bit_reverse(size_t n, const size_t bits); +size_t bit_reverse(size_t n, size_t bits); size_t next_power_of_two(size_t n); template