forked from cppcheck-opensource/cppcheck
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmicrosoft_gsl.cpp
More file actions
72 lines (57 loc) · 1.39 KB
/
Copy pathmicrosoft_gsl.cpp
File metadata and controls
72 lines (57 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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;
}