diff --git a/cfg/microsoft_gsl.cfg b/cfg/microsoft_gsl.cfg new file mode 100644 index 00000000000..07fbfcb74a6 --- /dev/null +++ b/cfg/microsoft_gsl.cfg @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + 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..4241cce045d --- /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 --suppress=autoNoType 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(const 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..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 @@ -563,6 +563,9 @@ function check_file { lua_fn cppcheck_run --library="$lib" "${DIR}""$f" ;; + microsoft_gsl.cpp) + cppcheck_run --suppress=autoNoType --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 @@ +