Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
e8ebd12
Initial plan
Copilot Dec 2, 2025
3e8d51e
Add cppcheck and clang-tidy static analysis workflow
Copilot Dec 2, 2025
4d76416
Restore compile_commands.json symlink
Copilot Dec 2, 2025
6c7338f
Add explicit permissions to static analysis workflow
Copilot Dec 2, 2025
c952138
Fix: cppcheck suppression for missing system includes
97gamjak Dec 7, 2025
5d455af
Fix: update .gitignore to include compile_commands.json and remove sy…
97gamjak Dec 7, 2025
55b9706
fix: Enhance static analysis configuration and add cppcheck script
97gamjak Dec 10, 2025
795b9de
Merge pull request #65 from 97gamjak/fix_cpp_errors
97gamjak Dec 10, 2025
5ff87f3
feat: Add include guards to new compile.hpp; enhance error.hpp and qu…
97gamjak Dec 11, 2025
e7f7839
Update include/mstd/error.hpp
97gamjak Dec 11, 2025
84ff357
Update include/mstd/error.hpp
97gamjak Dec 11, 2025
3c59c27
feat: Add documentation for MSTD_IGNORE_BUGGY_CODE macro and enhance …
97gamjak Dec 11, 2025
c3d4c23
Merge branch 'feature/MSTD-65-create-buggy-static-asser-for-single-fi…
97gamjak Dec 11, 2025
d44a152
docs: Update CHANGELOG.md to include new error handling and compilati…
97gamjak Dec 11, 2025
d003e44
Merge pull request #70 from 97gamjak/feature/MSTD-65-create-buggy-sta…
97gamjak Dec 11, 2025
e59f872
Merge remote-tracking branch 'origin/dev' into copilot/add-cpp-check-…
97gamjak Dec 20, 2025
ece5ce8
feat: enhance static analysis workflow and add buggy header warnings
97gamjak Dec 20, 2025
8880701
feat: update buggy marker variables to include library and header names
97gamjak Dec 20, 2025
b67d5de
feat: update buggy marker macros to use library and header names in n…
97gamjak Dec 20, 2025
7a432b1
feat: enhance buggy library and header warnings with unique namespace…
97gamjak Dec 20, 2025
51cff2a
feat: update lie potential evaluation method for clarity and consistency
97gamjak Dec 20, 2025
5fca45b
feat: streamline static analysis workflow by removing clang-tidy and …
97gamjak Dec 20, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .cppcheck.suppress
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
unusedFunction
unusedStructMember
unusedFunction
23 changes: 23 additions & 0 deletions .devops.toml
Original file line number Diff line number Diff line change
@@ -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"
60 changes: 60 additions & 0 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ checks.egg-info/
__pycache__/
.venv
docs/output/
compile_commands.json
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

<!-- insertion marker -->
## [0.0.2](https://github.com/97gamjak/mstd/releases/tag/0.0.2) - 2025-11-20

Expand Down
1 change: 0 additions & 1 deletion compile_commands.json

This file was deleted.

43 changes: 43 additions & 0 deletions include/mstd/compile.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*****************************************************************************
<GPL_HEADER>

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 <http://www.gnu.org/licenses/>.

<GPL_HEADER>
******************************************************************************/

#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__
47 changes: 42 additions & 5 deletions include/mstd/error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,58 @@

#include <type_traits>

#include "compile.hpp"

namespace mstd
{
// clang-format off
/**
* @brief a struct that is always false
*
* @tparam T
*
* @tparam T
*/
template <typename T>
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<void>::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__
14 changes: 11 additions & 3 deletions include/mstd/physics/potentials/lie_potential.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -96,7 +104,7 @@ namespace mstd
constexpr LieShiftedPotential(Rep c1, Rep c2, Rep rc)
: LiePotential<M, N, Rep>(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.
Expand Down
4 changes: 4 additions & 0 deletions include/mstd/quantity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions include/mstd/quantity/dim.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <cstddef>

#include "dim_details.hpp"
Expand Down
4 changes: 4 additions & 0 deletions include/mstd/quantity/dim_details.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions include/mstd/quantity/dim_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
4 changes: 4 additions & 0 deletions include/mstd/quantity/dim_operations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
4 changes: 4 additions & 0 deletions include/mstd/quantity/dim_ratio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
4 changes: 4 additions & 0 deletions include/mstd/quantity/dim_ratio_details.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions include/mstd/quantity/dim_ratio_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions include/mstd/quantity/dim_ratio_operations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
12 changes: 10 additions & 2 deletions include/mstd/quantity/enums.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <cstddef>

#include "mstd/enum.hpp"
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions include/mstd/quantity/quantity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <type_traits>

#include "mstd/type_traits/quantity_traits.hpp"
Expand Down
Loading