-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathtest.cpp
More file actions
44 lines (35 loc) · 1.56 KB
/
test.cpp
File metadata and controls
44 lines (35 loc) · 1.56 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
#include <cstdint>
// Non-compliant global variables (namespace scope, dynamically initialized or
// mutable)
std::int32_t f1();
std::int32_t g1{f1()}; // NON_COMPLIANT - dynamic initialization
const std::int32_t g2{
g1}; // NON_COMPLIANT - dynamic initialization (depends on g1)
const std::int32_t g3{42}; // COMPLIANT - const with static initialization
constexpr std::int32_t g4{0}; // COMPLIANT - constexpr
namespace {
std::int32_t g5{0}; // NON_COMPLIANT - mutable namespace scope variable
constexpr std::int32_t g6{100}; // COMPLIANT - constexpr
const std::int32_t g7{100}; // COMPLIANT - const with static initialization
constexpr std::int32_t f2() { return 42; }
constexpr std::int32_t g8{f2()}; // COMPLIANT - constexpr
} // namespace
struct ComplexInit {
ComplexInit() {}
};
const ComplexInit g9{}; // NON_COMPLIANT - dynamic initialization
std::int32_t g10{0}; // NON_COMPLIANT - mutable namespace scope variable
const std::int32_t g11{f1()}; // NON_COMPLIANT - dynamic initialization
class StaticMember {
std::int32_t m1;
static std::int32_t m2; // NON_COMPLIANT - class static data member
static std::int32_t m3; // marked non_compliant at definition below
static constexpr std::int32_t m4{0}; // COMPLIANT - constexpr static member
static const std::int32_t m5;
};
std::int32_t StaticMember::m3 =
0; // NON_COMPLIANT - class static data member definition
const std::int32_t StaticMember::m5 =
42; // COMPLIANT - const with static initialization
constexpr auto g12 = // COMPLIANT - constexpr lambda
[](auto x, auto y) { return x + y; };