diff --git a/.cppcheck.suppress b/.cppcheck.suppress index 935ac34..e0e3a7f 100644 --- a/.cppcheck.suppress +++ b/.cppcheck.suppress @@ -1,2 +1 @@ -unusedFunction -unusedStructMember \ No newline at end of file +unusedFunction \ No newline at end of file diff --git a/.devops.toml b/.devops.toml new file mode 100644 index 0000000..185a95c --- /dev/null +++ b/.devops.toml @@ -0,0 +1,23 @@ +# DevOps Configuration File + +[exclude] +buggy_cpp_macros = ["MSTD_WARN_BUGGY_HEADER", "MSTD_WARN_BUGGY_LIBRARY"] + +[logging] +#global_level = "INFO" +#utils_level = "INFO" +#config_level = "INFO" +#cpp_level = "INFO" + +[git] +#tag_prefix = "" +#empty_tag_list_allowed = true + +[cpp] +#style_checks = true +#license_header_check = true +#check_only_staged_files = false +license_header = "config/licenseHeader.txt" + +[file] +#encoding = "utf-8" diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml new file mode 100644 index 0000000..20707ca --- /dev/null +++ b/.github/workflows/static-analysis.yml @@ -0,0 +1,60 @@ +name: Static Analysis + +on: + pull_request: + branches: + - '*' + workflow_dispatch: + +permissions: + contents: read + +jobs: + cppcheck: + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + + - name: Install cppcheck + run: | + sudo apt update + sudo apt install -y cppcheck + + - name: Run cppcheck + run: | + cppcheck --enable=all \ + --enable=performance \ + --enable=style \ + --enable=information \ + --enable=portability \ + --error-exitcode=1 \ + --suppressions-list=.cppcheck.suppress \ + --suppress=missingIncludeSystem \ + --inline-suppr \ + --inconclusive \ + -I include \ + include test + + clang-tidy: + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: 3.13 + cache: 'pip' + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -e external/devops + + - name: Install clang-tidy and dependencies + run: | + cpp_checks --dirs include --dirs test \ No newline at end of file diff --git a/.gitignore b/.gitignore index 2a23e7d..32cd6fe 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ checks.egg-info/ __pycache__/ .venv docs/output/ +compile_commands.json diff --git a/CHANGELOG.md b/CHANGELOG.md index 85cdd96..4a01cd2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,14 @@ All notable changes to this project will be documented in this file. - Add "static inline constexpr" as key sequence order cpp rule - Add "update_changelog.py" script to update CHANGELOG.md automatically based on version input +### Error Handling + +- Add compile time warning macros for buggy libraries and buggy headers (used atm in quantity lib as long as it is not fixed) + +### Compilation + +- Add Compile flag `MSTD_IGNORE_BUGGY_CODE` to ignore any kind of warnings for buggy libraries or headers + ## [0.0.2](https://github.com/97gamjak/mstd/releases/tag/0.0.2) - 2025-11-20 diff --git a/compile_commands.json b/compile_commands.json deleted file mode 120000 index 4503a4b..0000000 --- a/compile_commands.json +++ /dev/null @@ -1 +0,0 @@ -.build/compile_commands.json \ No newline at end of file diff --git a/external/devops b/external/devops index a361ebc..7d38a4d 160000 --- a/external/devops +++ b/external/devops @@ -1 +1 @@ -Subproject commit a361ebc7702c24f5b16ec1b999ce3b95f69805c3 +Subproject commit 7d38a4d40ec2cbabc8a43312fc9e675c2d9ccde0 diff --git a/include/mstd/compile.hpp b/include/mstd/compile.hpp new file mode 100644 index 0000000..34c8b09 --- /dev/null +++ b/include/mstd/compile.hpp @@ -0,0 +1,43 @@ +/***************************************************************************** + + + mstd library + Copyright (C) 2025-now Jakob Gamper + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + + +******************************************************************************/ + +#ifndef __MSTD_COMPILE_HPP__ +#define __MSTD_COMPILE_HPP__ + +/** + * @brief Ignore buggy code + * + * Define this macro to ignore code that is known to be buggy in certain + * environments/libraries/compilers. + * + * @note at the moment the exact value of this macro does not matter + * as long as it is defined or not defined + * + */ +#ifdef MSTD_IGNORE_BUGGY_CODE +#undef MSTD_IGNORE_BUGGY_CODE +#define MSTD_IGNORE_BUGGY_CODE 1 +#else +#define MSTD_IGNORE_BUGGY_CODE 0 +#endif + +#endif // __MSTD_COMPILE_HPP__ \ No newline at end of file diff --git a/include/mstd/error.hpp b/include/mstd/error.hpp index 4269b71..90f18e2 100644 --- a/include/mstd/error.hpp +++ b/include/mstd/error.hpp @@ -25,21 +25,58 @@ #include +#include "compile.hpp" + namespace mstd { - // clang-format off /** * @brief a struct that is always false - * - * @tparam T + * + * @tparam T */ template - struct always_false : std::false_type{}; - // clang-format on + struct always_false : std::false_type + { + }; } // namespace mstd +#define MSTD_CAT(a, b) a##b +#define MSTD_CAT2(a, b) MSTD_CAT(a, b) + #define MSTD_COMPILE_FAIL(msg) \ static_assert(::mstd::always_false::value, msg) +#define MSTD_WARN_BUGGY_LIBRARY(library_name) +#define MSTD_WARN_BUGGY_HEADER(header_file) + +#if !MSTD_IGNORE_BUGGY_CODE + +#undef MSTD_WARN_BUGGY_LIBRARY +#undef MSTD_WARN_BUGGY_HEADER + +/** + * @brief Warn about a buggy library + */ +#define MSTD_WARN_BUGGY_LIBRARY(library_name) \ + namespace MSTD_CAT2(mstd::buggy, __COUNTER__) \ + { \ + [[deprecated("Buggy library: " library_name " — don't use it!")]] \ + inline int buggy_marker = 0; \ + inline int buggy_marker_alias = buggy_marker; \ + } + +/** + * @brief Warn about a buggy header + */ +#define MSTD_WARN_BUGGY_HEADER(header_file) \ + namespace MSTD_CAT2(mstd::buggy, __COUNTER__) \ + { \ + [[deprecated("Buggy header: " header_file " — don't use it!")]] \ + inline int buggy_marker = 0; \ + inline int buggy_marker_alias = buggy_marker; \ + } + +#endif + #endif // __MSTD_ERROR_HPP__ \ No newline at end of file diff --git a/include/mstd/physics/potentials/lie_potential.hpp b/include/mstd/physics/potentials/lie_potential.hpp index 6653dbe..ea278eb 100644 --- a/include/mstd/physics/potentials/lie_potential.hpp +++ b/include/mstd/physics/potentials/lie_potential.hpp @@ -46,8 +46,16 @@ namespace mstd Rep _coeff2{}; public: - /// @brief Constructs the potential with prefactors for the attractive - /// and repulsive terms. + /** + * @brief Constructs the potential with prefactors for the attractive + * and repulsive terms. + * + * @note The coefficients correspond to the terms + * \f$-c_1 r^{-M} + c_2 r^{-N}\f$ in the potential expression. + * + * @param c1 Coefficient for the attractive term. + * @param c2 Coefficient for the repulsive term. + */ constexpr LiePotential(Rep c1, Rep c2) : _coeff1(c1), _coeff2(c2) {} /// @brief Evaluates only the potential energy at a distance @p r. @@ -96,7 +104,7 @@ namespace mstd constexpr LieShiftedPotential(Rep c1, Rep c2, Rep rc) : LiePotential(c1, c2), _radialCutoff(rc) { - std::tie(_energyCutoff, _forceCutoff) = eval(_radialCutoff); + std::tie(_energyCutoff, _forceCutoff) = _Base::eval(rc); } /// @brief Energy corrected so that it vanishes at the cutoff. diff --git a/include/mstd/quantity.hpp b/include/mstd/quantity.hpp index bf51a41..1ada8cb 100644 --- a/include/mstd/quantity.hpp +++ b/include/mstd/quantity.hpp @@ -23,6 +23,10 @@ #ifndef __MSTD_UNITS_HPP__ #define __MSTD_UNITS_HPP__ +#include "mstd/error.hpp" // IWYU pragma: export + +MSTD_WARN_BUGGY_LIBRARY("mstd/quantity.hpp") + #include "mstd/type_traits/quantity_traits.hpp" // IWYU pragma: export #include "quantity/dim.hpp" // IWYU pragma: export #include "quantity/dim_impl.hpp" // IWYU pragma: export diff --git a/include/mstd/quantity/dim.hpp b/include/mstd/quantity/dim.hpp index bb5550e..d7af790 100644 --- a/include/mstd/quantity/dim.hpp +++ b/include/mstd/quantity/dim.hpp @@ -23,6 +23,10 @@ #ifndef __MSTD_UNITS_DIMENSION_HPP__ #define __MSTD_UNITS_DIMENSION_HPP__ +#include "mstd/error.hpp" + +MSTD_WARN_BUGGY_HEADER("mstd/quantity/dim.hpp") + #include #include "dim_details.hpp" diff --git a/include/mstd/quantity/dim_details.hpp b/include/mstd/quantity/dim_details.hpp index 9115af4..76ca756 100644 --- a/include/mstd/quantity/dim_details.hpp +++ b/include/mstd/quantity/dim_details.hpp @@ -23,6 +23,10 @@ #ifndef __MSTD_DIM_DETAILS_HPP__ #define __MSTD_DIM_DETAILS_HPP__ +#include "mstd/error.hpp" + +MSTD_WARN_BUGGY_HEADER("mstd/quantity/dim_details.hpp") + #include "mstd/pack.hpp" namespace mstd diff --git a/include/mstd/quantity/dim_impl.hpp b/include/mstd/quantity/dim_impl.hpp index 975c55d..732ae73 100644 --- a/include/mstd/quantity/dim_impl.hpp +++ b/include/mstd/quantity/dim_impl.hpp @@ -23,6 +23,10 @@ #ifndef __MSTD_DIMENSION_IMPL_HPP__ #define __MSTD_DIMENSION_IMPL_HPP__ +#include "mstd/error.hpp" + +MSTD_WARN_BUGGY_HEADER("mstd/quantity/dim_impl.hpp") + #include "dim.hpp" #include "dim_operations.hpp" diff --git a/include/mstd/quantity/dim_operations.hpp b/include/mstd/quantity/dim_operations.hpp index cecf6a6..b8f51ad 100644 --- a/include/mstd/quantity/dim_operations.hpp +++ b/include/mstd/quantity/dim_operations.hpp @@ -23,6 +23,10 @@ #ifndef __MSTD_DIM_OPERATIONS_HPP__ #define __MSTD_DIM_OPERATIONS_HPP__ +#include "mstd/error.hpp" + +MSTD_WARN_BUGGY_HEADER("mstd/quantity/dim_operations.hpp") + #include "dim.hpp" #include "dim_details.hpp" diff --git a/include/mstd/quantity/dim_ratio.hpp b/include/mstd/quantity/dim_ratio.hpp index 347e905..87256ba 100644 --- a/include/mstd/quantity/dim_ratio.hpp +++ b/include/mstd/quantity/dim_ratio.hpp @@ -23,6 +23,10 @@ #ifndef __MSTD_DIM_RATIO_HPP__ #define __MSTD_DIM_RATIO_HPP__ +#include "mstd/error.hpp" + +MSTD_WARN_BUGGY_HEADER("mstd/quantity/dim_ratio.hpp") + #include "enums.hpp" #include "mstd/pack.hpp" diff --git a/include/mstd/quantity/dim_ratio_details.hpp b/include/mstd/quantity/dim_ratio_details.hpp index 0b329f0..69783a4 100644 --- a/include/mstd/quantity/dim_ratio_details.hpp +++ b/include/mstd/quantity/dim_ratio_details.hpp @@ -23,6 +23,10 @@ #ifndef __MSTD_DIM_RATIO_DETAILS_HPP__ #define __MSTD_DIM_RATIO_DETAILS_HPP__ +#include "mstd/error.hpp" + +MSTD_WARN_BUGGY_HEADER("mstd/quantity/dim_ratio_details.hpp") + #include "dim_details.hpp" #include "dim_ratio.hpp" #include "mstd/pack.hpp" diff --git a/include/mstd/quantity/dim_ratio_impl.hpp b/include/mstd/quantity/dim_ratio_impl.hpp index d9dbcb5..b85084d 100644 --- a/include/mstd/quantity/dim_ratio_impl.hpp +++ b/include/mstd/quantity/dim_ratio_impl.hpp @@ -23,6 +23,10 @@ #ifndef __MSTD_DIM_RATIO_IMPL_HPP__ #define __MSTD_DIM_RATIO_IMPL_HPP__ +#include "mstd/error.hpp" + +MSTD_WARN_BUGGY_HEADER("mstd/quantity/dim_ratio_impl.hpp") + #include "dim_ratio.hpp" #include "dim_ratio_operations.hpp" #include "mstd/ratio.hpp" diff --git a/include/mstd/quantity/dim_ratio_operations.hpp b/include/mstd/quantity/dim_ratio_operations.hpp index 05cf3e9..63cdec8 100644 --- a/include/mstd/quantity/dim_ratio_operations.hpp +++ b/include/mstd/quantity/dim_ratio_operations.hpp @@ -23,6 +23,10 @@ #ifndef __MSTD_DIM_RATIO_OPERATIONS_HPP__ #define __MSTD_DIM_RATIO_OPERATIONS_HPP__ +#include "mstd/error.hpp" + +MSTD_WARN_BUGGY_HEADER("mstd/quantity/dim_ratio_operations.hpp") + #include "dim_ratio.hpp" #include "dim_ratio_details.hpp" diff --git a/include/mstd/quantity/enums.hpp b/include/mstd/quantity/enums.hpp index d44744f..aa10c83 100644 --- a/include/mstd/quantity/enums.hpp +++ b/include/mstd/quantity/enums.hpp @@ -23,6 +23,10 @@ #ifndef __MSTD_UNITS_ENUMS_HPP__ #define __MSTD_UNITS_ENUMS_HPP__ +#include "mstd/error.hpp" + +MSTD_WARN_BUGGY_HEADER("mstd/quantity/enums.hpp") + #include #include "mstd/enum.hpp" @@ -54,7 +58,7 @@ namespace mstd X(Amount) \ X(Luminous) - MSTD_ENUM(SIDimId, size_t, SIDIMID_LIST) + MSTD_ENUM(SIDimId, size_t, SIDIMID_LIST) // cppcheck-suppress syntaxError /** * @brief Enumeration of the extra dimension IDs. @@ -72,7 +76,11 @@ namespace mstd X(Info) \ X(Count) - MSTD_ENUM(ExtraDimId, size_t, EXTRADIMID_LIST) + MSTD_ENUM( + ExtraDimId, + size_t, + EXTRADIMID_LIST + ) // cppcheck-suppress syntaxError // NOLINTEND } // namespace mstd diff --git a/include/mstd/quantity/quantity.hpp b/include/mstd/quantity/quantity.hpp index 54996c9..18d0a99 100644 --- a/include/mstd/quantity/quantity.hpp +++ b/include/mstd/quantity/quantity.hpp @@ -23,6 +23,10 @@ #ifndef __MSTD_UNITS_QUANTITY_HPP__ #define __MSTD_UNITS_QUANTITY_HPP__ +#include "mstd/error.hpp" + +MSTD_WARN_BUGGY_LIBRARY("mstd/quantity.hpp") + #include #include "mstd/type_traits/quantity_traits.hpp" diff --git a/include/mstd/quantity/quantity_impl.hpp b/include/mstd/quantity/quantity_impl.hpp index e196c72..3294473 100644 --- a/include/mstd/quantity/quantity_impl.hpp +++ b/include/mstd/quantity/quantity_impl.hpp @@ -23,6 +23,10 @@ #ifndef __MSTD_UNITS_QUANTITY_IMPL_HPP__ #define __MSTD_UNITS_QUANTITY_IMPL_HPP__ +#include "mstd/error.hpp" + +MSTD_WARN_BUGGY_HEADER("mstd/quantity/quantity_impl.hpp") + #include "quantity.hpp" #include "unit_impl.hpp" diff --git a/include/mstd/quantity/unit.hpp b/include/mstd/quantity/unit.hpp index 1caec56..9627bb8 100644 --- a/include/mstd/quantity/unit.hpp +++ b/include/mstd/quantity/unit.hpp @@ -23,6 +23,10 @@ #ifndef __MSTD_UNITS_UNIT_HPP__ #define __MSTD_UNITS_UNIT_HPP__ +#include "mstd/error.hpp" + +MSTD_WARN_BUGGY_HEADER("mstd/quantity/unit.hpp") + #include "dim_details.hpp" #include "dim_ratio.hpp" #include "mstd/error.hpp" diff --git a/include/mstd/quantity/unit_details.hpp b/include/mstd/quantity/unit_details.hpp index e4815a4..2953ad4 100644 --- a/include/mstd/quantity/unit_details.hpp +++ b/include/mstd/quantity/unit_details.hpp @@ -23,6 +23,10 @@ #ifndef __MSTD_UNITS_DETAILS_HPP__ #define __MSTD_UNITS_DETAILS_HPP__ +#include "mstd/error.hpp" + +MSTD_WARN_BUGGY_HEADER("mstd/quantity/unit_details.hpp") + #include "dim.hpp" #include "dim_ratio_operations.hpp" #include "mstd/math.hpp" diff --git a/include/mstd/quantity/unit_impl.hpp b/include/mstd/quantity/unit_impl.hpp index 461f0eb..272a516 100644 --- a/include/mstd/quantity/unit_impl.hpp +++ b/include/mstd/quantity/unit_impl.hpp @@ -23,6 +23,10 @@ #ifndef __MSTD_UNIT_IMPL_HPP__ #define __MSTD_UNIT_IMPL_HPP__ +#include "mstd/error.hpp" + +MSTD_WARN_BUGGY_HEADER("mstd/quantity/unit_impl.hpp") + #include #include "dim_impl.hpp" diff --git a/include/mstd/quantity/unit_operations.hpp b/include/mstd/quantity/unit_operations.hpp index 9e650a6..659595c 100644 --- a/include/mstd/quantity/unit_operations.hpp +++ b/include/mstd/quantity/unit_operations.hpp @@ -23,6 +23,10 @@ #ifndef __MSTD_UNIT_OPERATIONS_HPP__ #define __MSTD_UNIT_OPERATIONS_HPP__ +#include "mstd/error.hpp" + +MSTD_WARN_BUGGY_HEADER("mstd/quantity/unit_operations.hpp") + #include "mstd/pack.hpp" #include "mstd/ratio.hpp" #include "unit_details.hpp" diff --git a/scripts/cppcheck.sh b/scripts/cppcheck.sh new file mode 100755 index 0000000..94769a7 --- /dev/null +++ b/scripts/cppcheck.sh @@ -0,0 +1,12 @@ +cppcheck --enable=all \ + --enable=performance \ + --enable=style \ + --enable=information \ + --enable=portability \ + --error-exitcode=1 \ + --suppressions-list=.cppcheck.suppress \ + --suppress=missingIncludeSystem \ + --inline-suppr \ + --inconclusive \ + -I include \ + include test diff --git a/test/math/test_cpow.cpp b/test/math/test_cpow.cpp index 1cfd182..d078eda 100644 --- a/test/math/test_cpow.cpp +++ b/test/math/test_cpow.cpp @@ -1,3 +1,25 @@ +/***************************************************************************** + + + mstd library + Copyright (C) 2025-now Jakob Gamper + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + + +******************************************************************************/ + #include #include #include