Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 17 additions & 0 deletions cfg/microsoft_gsl.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0"?>
<def>
<define name="Expects(x)" value=""/>
<define name="Ensures(x)" value=""/>
<define name="GSL_SUPPRESS(x)" value=""/>
<podtype name="gsl::index" sign="s"/>
Comment thread
chrchr-github marked this conversation as resolved.
<podtype name="gsl::byte" sign="u" size="1"/><!-- Deprecated in GSL -->
<container id="gslSpan" startPattern="gsl :: span" inherits="stdSpan">
</container>
<smart-pointer class-name="gsl::owner"/>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please group the smart pointers together and add <unique/> where appropriate.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added the </unique> tag accordingly

<smart-pointer class-name="gsl::not_null"/>
<smart-pointer class-name="gsl::unique_ptr"><!-- Deprecated in GSL -->
<unique/>
</smart-pointer>
<smart-pointer class-name="gsl::shared_ptr"/><!-- Deprecated in GSL -->
<smart-pointer class-name="gsl::strict_not_null"/><!-- non-existing in C++ Core Guidelines -->
</def>
1 change: 1 addition & 0 deletions man/manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -1161,6 +1161,7 @@ To use a `.cfg` file shipped with Cppcheck, pass the `--library=<lib>` 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` | | |
Expand Down
72 changes: 72 additions & 0 deletions test/cfg/microsoft_gsl.cpp
Original file line number Diff line number Diff line change
@@ -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 <vector>

// Guideline Support Library
#include <gsl/gsl>

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<int *> 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<int> s) -> int
{
GSL_SUPPRESS("bounds.1")
return s[0];
}

auto iterate_over_container_test(const std::vector<int> &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<int *> p)
{
Expects(p != nullptr);
*p = 42;
}

void strict_not_null_test(gsl::strict_not_null<int *> p)
{
Expects(p != nullptr);
*p = 42;
}

auto byte_test(gsl::byte b) -> gsl::byte
{
return b | 0x81;
}
5 changes: 4 additions & 1 deletion test/cfg/runtests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down
1 change: 1 addition & 0 deletions test/tools/donate_cpu_lib_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def test_library_includes(tmpdir):
_test_library_includes(tmpdir, ['posix', 'gnu', 'bsd', 'opengl'], '#include\t <GL/glut.h>')
_test_library_includes(tmpdir, ['posix', 'gnu', 'bsd', 'nspr'], '#include\t"prtypes.h"')
_test_library_includes(tmpdir, ['posix', 'gnu', 'bsd', 'lua'], '#include \t<lua.h>')
_test_library_includes(tmpdir, ['posix', 'gnu', 'bsd', 'microsoft_gsl'], '#include <gsl/gsl>')

def test_match_multiple_time(tmpdir):
libinc = LibraryIncludes()
Expand Down
1 change: 1 addition & 0 deletions tools/donate_cpu_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,7 @@ def __init__(self):
'wxwidgets': ['<wx/', '"wx/'],
'zephyr': ['<zephyr/'],
'zlib': ['<zlib.h>'],
'microsoft_gsl': ['<gsl/gsl>'],
}

self.__library_includes_re = {}
Expand Down
1 change: 1 addition & 0 deletions win_installer/cppcheck.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
<File Id='lua.cfg' Name='lua.cfg' Source='$(var.CfgsDir)\lua.cfg' />
<File Id='mfc.cfg' Name='mfc.cfg' Source='$(var.CfgsDir)\mfc.cfg' />
<File Id='microsoft_atl.cfg' Name='microsoft_atl.cfg' Source='$(var.CfgsDir)\microsoft_atl.cfg' />
<File Id='microsoft_gsl.cfg' Name='microsoft_gsl.cfg' Source='$(var.CfgsDir)\microsoft_gsl.cfg' />
<File Id='microsoft_sal.cfg' Name='microsoft_sal.cfg' Source='$(var.CfgsDir)\microsoft_sal.cfg' />
<File Id='microsoft_unittest.cfg' Name='microsoft_unittest.cfg' Source='$(var.CfgsDir)\microsoft_unittest.cfg' />
<File Id='motif.cfg' Name='motif.cfg' Source='$(var.CfgsDir)\motif.cfg' />
Expand Down
Loading