From 5c657c3079e38dc68b436848190ea5782b4ba34d Mon Sep 17 00:00:00 2001 From: Felix Patschkowski <49550034+Patschkowski@users.noreply.github.com> Date: Thu, 16 Jul 2026 08:04:17 +0800 Subject: [PATCH 1/3] Added configuration file for Microsoft.GSL library --- cfg/microsoft_gsl.cfg | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 cfg/microsoft_gsl.cfg diff --git a/cfg/microsoft_gsl.cfg b/cfg/microsoft_gsl.cfg new file mode 100644 index 00000000000..97ba7534706 --- /dev/null +++ b/cfg/microsoft_gsl.cfg @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + From 4f86357addc2b28c92cb3609c2200d5aa48b4ef1 Mon Sep 17 00:00:00 2001 From: Felix Patschkowski Date: Fri, 17 Jul 2026 21:16:05 +0700 Subject: [PATCH 2/3] Added tests for CI/CD --- cfg/microsoft_gsl.cfg | 12 +++--- man/manual.md | 1 + test/cfg/microsoft_gsl.cpp | 72 +++++++++++++++++++++++++++++++ test/cfg/runtests.sh | 3 ++ test/tools/donate_cpu_lib_test.py | 1 + tools/donate_cpu_lib.py | 1 + win_installer/cppcheck.wxs | 1 + 7 files changed, 85 insertions(+), 6 deletions(-) create mode 100644 test/cfg/microsoft_gsl.cpp diff --git a/cfg/microsoft_gsl.cfg b/cfg/microsoft_gsl.cfg index 97ba7534706..07fbfcb74a6 100644 --- a/cfg/microsoft_gsl.cfg +++ b/cfg/microsoft_gsl.cfg @@ -4,14 +4,14 @@ + - - - - - - + + + + + diff --git a/man/manual.md b/man/manual.md index 47a3a43fd36..7db916d4777 100644 --- a/man/manual.md +++ b/man/manual.md @@ -1161,6 +1161,7 @@ To use a `.cfg` file shipped with Cppcheck, pass the `--library=` option. T | `lua.cfg` | | | | `mfc.cfg` | [MFC](https://learn.microsoft.com/en-us/cpp/mfc/mfc-desktop-applications) | | | `microsoft_atl.cfg` | [ATL](https://learn.microsoft.com/en-us/cpp/atl/active-template-library-atl-concepts) | | +| `microsoft_gsl.cfg` | [Microsoft.GSL](https://github.com/microsoft/gsl) | | | `microsoft_sal.cfg` | [SAL annotations](https://learn.microsoft.com/en-us/cpp/c-runtime-library/sal-annotations) | | | `microsoft_unittest.cfg` | [CppUnitTest](https://learn.microsoft.com/en-us/visualstudio/test/microsoft-visualstudio-testtools-cppunittestframework-api-reference) | | | `motif.cfg` | | | diff --git a/test/cfg/microsoft_gsl.cpp b/test/cfg/microsoft_gsl.cpp new file mode 100644 index 00000000000..f46ec3a8b54 --- /dev/null +++ b/test/cfg/microsoft_gsl.cpp @@ -0,0 +1,72 @@ +// Test library configuration for microsoft_gsl.cfg +// +// Usage: +// $ cppcheck --check-library --library=microsoft_gsl --enable=style,information --inconclusive --error-exitcode=1 --inline-suppr test/cfg/microsoft_gsl.cpp +// => +// No warnings about bad library configuration, unmatched suppressions, etc. exitcode=0 +// + +// C++ Standard Library +#include + +// Guideline Support Library +#include + +struct owner_type +{ + owner_type() = default; + owner_type(const owner_type &) = delete; + owner_type(owner_type &&) = default; + + ~owner_type() { delete ptr_; } + + auto operator=(const owner_type &) -> owner_type & = delete; + auto operator=(owner_type &&) -> owner_type & = default; + +private: + gsl::owner ptr_{new int(42)}; +}; + +auto pre_and_post_condition_test(int i) -> int +{ + Expects(i > 0); + + const auto result{i * 2}; + + Ensures(result > 0); + return result; +} + +auto suppress_macro_test(std::span s) -> int +{ + GSL_SUPPRESS("bounds.1") + return s[0]; +} + +auto iterate_over_container_test(std::vector v) -> int +{ + int sum{0}; + + for (gsl::index i{0}; i < v.size(); ++i) + { + sum += v[i]; + } + return sum; +} + +void not_null_test(gsl::not_null p) +{ + Expects(p != nullptr); + *p = 42; +} + +void strict_not_null_test(gsl::strict_not_null p) +{ + Expects(p != nullptr); + *p = 42; +} + +auto byte_test(gsl::byte b) -> gsl::byte +{ + return b | 0x81; +} diff --git a/test/cfg/runtests.sh b/test/cfg/runtests.sh index c8c1515e66c..7df0ff98d88 100755 --- a/test/cfg/runtests.sh +++ b/test/cfg/runtests.sh @@ -563,6 +563,9 @@ function check_file { lua_fn cppcheck_run --library="$lib" "${DIR}""$f" ;; + microsoft_gsl.cpp) + cppcheck_run --library="$lib" "${DIR}""$f" + ;; mfc.cpp) mfc_fn cppcheck_run --platform=win64 --library="$lib" "${DIR}""$f" diff --git a/test/tools/donate_cpu_lib_test.py b/test/tools/donate_cpu_lib_test.py index e00a3d296a0..141781192aa 100644 --- a/test/tools/donate_cpu_lib_test.py +++ b/test/tools/donate_cpu_lib_test.py @@ -58,6 +58,7 @@ def test_library_includes(tmpdir): _test_library_includes(tmpdir, ['posix', 'gnu', 'bsd', 'opengl'], '#include\t ') _test_library_includes(tmpdir, ['posix', 'gnu', 'bsd', 'nspr'], '#include\t"prtypes.h"') _test_library_includes(tmpdir, ['posix', 'gnu', 'bsd', 'lua'], '#include \t') + _test_library_includes(tmpdir, ['posix', 'gnu', 'bsd', 'microsoft_gsl'], '#include ') def test_match_multiple_time(tmpdir): libinc = LibraryIncludes() diff --git a/tools/donate_cpu_lib.py b/tools/donate_cpu_lib.py index c292d2b9a13..ed345cb10c9 100644 --- a/tools/donate_cpu_lib.py +++ b/tools/donate_cpu_lib.py @@ -723,6 +723,7 @@ def __init__(self): 'wxwidgets': [''], + 'microsoft_gsl': [''], } self.__library_includes_re = {} diff --git a/win_installer/cppcheck.wxs b/win_installer/cppcheck.wxs index e7b597e2046..91d08c1c946 100644 --- a/win_installer/cppcheck.wxs +++ b/win_installer/cppcheck.wxs @@ -107,6 +107,7 @@ + From 6f9d8cb7de5354c40e27d7380b35a90d856922a8 Mon Sep 17 00:00:00 2001 From: Felix Patschkowski Date: Sat, 18 Jul 2026 00:43:00 +0700 Subject: [PATCH 3/3] Fixed pipeline errors --- test/cfg/microsoft_gsl.cpp | 4 ++-- test/cfg/runtests.sh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/cfg/microsoft_gsl.cpp b/test/cfg/microsoft_gsl.cpp index f46ec3a8b54..4241cce045d 100644 --- a/test/cfg/microsoft_gsl.cpp +++ b/test/cfg/microsoft_gsl.cpp @@ -1,7 +1,7 @@ // Test library configuration for microsoft_gsl.cfg // // Usage: -// $ cppcheck --check-library --library=microsoft_gsl --enable=style,information --inconclusive --error-exitcode=1 --inline-suppr test/cfg/microsoft_gsl.cpp +// $ cppcheck --check-library --library=microsoft_gsl --enable=style,information --inconclusive --error-exitcode=1 --inline-suppr --suppress=autoNoType test/cfg/microsoft_gsl.cpp // => // No warnings about bad library configuration, unmatched suppressions, etc. exitcode=0 // @@ -43,7 +43,7 @@ auto suppress_macro_test(std::span s) -> int return s[0]; } -auto iterate_over_container_test(std::vector v) -> int +auto iterate_over_container_test(const std::vector &v) -> int { int sum{0}; diff --git a/test/cfg/runtests.sh b/test/cfg/runtests.sh index 7df0ff98d88..4cf17b3a9df 100755 --- a/test/cfg/runtests.sh +++ b/test/cfg/runtests.sh @@ -549,7 +549,7 @@ function check_file { kde.cpp) # TODO: "kde-4config" is no longer commonly available in recent distros #kde_fn - cppcheck_run --library="$lib" --library=qt "${DIR}""$f" + cppcheck_run --library="$lib" --library=qt "${DIR}""$f" ;; libcurl.c) libcurl_fn @@ -564,7 +564,7 @@ function check_file { cppcheck_run --library="$lib" "${DIR}""$f" ;; microsoft_gsl.cpp) - cppcheck_run --library="$lib" "${DIR}""$f" + cppcheck_run --suppress=autoNoType --library="$lib" "${DIR}""$f" ;; mfc.cpp) mfc_fn