1*7c50187bSPascal Jungblut // RUN: %check_clang_tidy %s -check-suffixes=,DEFAULT cppcoreguidelines-avoid-non-const-global-variables %t
2*7c50187bSPascal Jungblut // RUN: %check_clang_tidy %s -check-suffixes=,INTERNAL-LINKAGE cppcoreguidelines-avoid-non-const-global-variables %t -- \
3*7c50187bSPascal Jungblut // RUN: -config="{CheckOptions: {cppcoreguidelines-avoid-non-const-global-variables.AllowInternalLinkage : 'true'}}"
489a1d03eSRichard 
589a1d03eSRichard int nonConstInt = 0;
689a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: variable 'nonConstInt' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
789a1d03eSRichard 
889a1d03eSRichard int &nonConstIntReference = nonConstInt;
989a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: variable 'nonConstIntReference' provides global access to a non-const object; consider making the referenced data 'const' [cppcoreguidelines-avoid-non-const-global-variables]
1089a1d03eSRichard 
1189a1d03eSRichard int *pointerToNonConstInt = &nonConstInt;
1289a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: variable 'pointerToNonConstInt' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
1389a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-2]]:6: warning: variable 'pointerToNonConstInt' provides global access to a non-const object; consider making the pointed-to data 'const' [cppcoreguidelines-avoid-non-const-global-variables]
1489a1d03eSRichard 
1589a1d03eSRichard int *const constPointerToNonConstInt = &nonConstInt;
1689a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: variable 'constPointerToNonConstInt' provides global access to a non-const object; consider making the pointed-to data 'const' [cppcoreguidelines-avoid-non-const-global-variables]
1789a1d03eSRichard 
1889a1d03eSRichard namespace namespace_name {
1989a1d03eSRichard int nonConstNamespaceInt = 0;
2089a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: variable 'nonConstNamespaceInt' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
2189a1d03eSRichard 
2289a1d03eSRichard const int constNamespaceInt = 0;
2389a1d03eSRichard } // namespace namespace_name
2489a1d03eSRichard 
2589a1d03eSRichard const int constInt = 0;
2689a1d03eSRichard 
2789a1d03eSRichard const int *pointerToConstInt = &constInt;
2889a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: variable 'pointerToConstInt' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
2989a1d03eSRichard 
3089a1d03eSRichard const int *const constPointerToConstInt = &constInt;
3189a1d03eSRichard 
3289a1d03eSRichard const int &constReferenceToConstInt = constInt;
3389a1d03eSRichard 
3489a1d03eSRichard constexpr int constexprInt = 0;
3589a1d03eSRichard 
function()3689a1d03eSRichard int function() {
3789a1d03eSRichard   int nonConstReturnValue = 0;
3889a1d03eSRichard   return nonConstReturnValue;
3989a1d03eSRichard }
4089a1d03eSRichard 
4189a1d03eSRichard namespace {
4289a1d03eSRichard int nonConstAnonymousNamespaceInt = 0;
43*7c50187bSPascal Jungblut // CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:5: warning: variable 'nonConstAnonymousNamespaceInt' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
44*7c50187bSPascal Jungblut // CHECK-MESSAGES-INTERNAL-LINKAGE-NOT: :[[@LINE-2]]:5: warning: variable 'nonConstAnonymousNamespaceInt' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
4589a1d03eSRichard } // namespace
4689a1d03eSRichard 
47*7c50187bSPascal Jungblut static int nonConstStaticInt = 0;
48*7c50187bSPascal Jungblut // CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:12: warning: variable 'nonConstStaticInt' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
49*7c50187bSPascal Jungblut // CHECK-MESSAGES-INTERNAL-LINKAGE-NOT: :[[@LINE-2]]:12: warning: variable 'nonConstStaticInt' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
50*7c50187bSPascal Jungblut 
51*7c50187bSPascal Jungblut static const int constStaticInt = 0;
52*7c50187bSPascal Jungblut 
5389a1d03eSRichard class DummyClass {
5489a1d03eSRichard public:
5589a1d03eSRichard   int nonConstPublicMemberVariable = 0;
5689a1d03eSRichard   const int constPublicMemberVariable = 0;
5789a1d03eSRichard 
5889a1d03eSRichard private:
5989a1d03eSRichard   int nonConstPrivateMemberVariable = 0;
6089a1d03eSRichard   const int constPrivateMemberVariable = 0;
6189a1d03eSRichard };
6289a1d03eSRichard 
6389a1d03eSRichard DummyClass nonConstClassInstance;
6489a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: variable 'nonConstClassInstance' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
6589a1d03eSRichard 
6689a1d03eSRichard DummyClass *pointerToNonConstDummyClass = &nonConstClassInstance;
6789a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: variable 'pointerToNonConstDummyClass' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
6889a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-2]]:13: warning: variable 'pointerToNonConstDummyClass' provides global access to a non-const object; consider making the pointed-to data 'const' [cppcoreguidelines-avoid-non-const-global-variables]
6989a1d03eSRichard 
7089a1d03eSRichard DummyClass &referenceToNonConstDummyClass = nonConstClassInstance;
7189a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: variable 'referenceToNonConstDummyClass' provides global access to a non-const object; consider making the referenced data 'const' [cppcoreguidelines-avoid-non-const-global-variables]
7289a1d03eSRichard 
7389a1d03eSRichard int *nonConstPointerToMember = &nonConstClassInstance.nonConstPublicMemberVariable;
7489a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: variable 'nonConstPointerToMember' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
7589a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-2]]:6: warning: variable 'nonConstPointerToMember' provides global access to a non-const object; consider making the pointed-to data 'const' [cppcoreguidelines-avoid-non-const-global-variables]
7689a1d03eSRichard int *const constPointerToNonConstMember = &nonConstClassInstance.nonConstPublicMemberVariable;
7789a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: variable 'constPointerToNonConstMember' provides global access to a non-const object; consider making the pointed-to data 'const' [cppcoreguidelines-avoid-non-const-global-variables]
7889a1d03eSRichard 
7989a1d03eSRichard const DummyClass constClassInstance;
8089a1d03eSRichard 
8189a1d03eSRichard DummyClass *const constPointerToNonConstDummyClass = &nonConstClassInstance;
8289a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: variable 'constPointerToNonConstDummyClass' provides global access to a non-const object; consider making the pointed-to data 'const' [cppcoreguidelines-avoid-non-const-global-variables]
8389a1d03eSRichard 
8489a1d03eSRichard const DummyClass *nonConstPointerToConstDummyClass = &constClassInstance;
8589a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: variable 'nonConstPointerToConstDummyClass' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
8689a1d03eSRichard 
8789a1d03eSRichard const DummyClass *const constPointerToConstDummyClass = &constClassInstance;
8889a1d03eSRichard 
8989a1d03eSRichard const int *const constPointerToConstMember = &constClassInstance.nonConstPublicMemberVariable;
9089a1d03eSRichard 
9189a1d03eSRichard const DummyClass &constReferenceToDummyClass = constClassInstance;
9289a1d03eSRichard 
9389a1d03eSRichard namespace namespace_name {
9489a1d03eSRichard DummyClass nonConstNamespaceClassInstance;
9589a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: variable 'nonConstNamespaceClassInstance' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
9689a1d03eSRichard 
9789a1d03eSRichard const DummyClass constDummyClassInstance;
9889a1d03eSRichard } // namespace namespace_name
9989a1d03eSRichard 
10089a1d03eSRichard // CHECKING FOR NON-CONST GLOBAL ENUM /////////////////////////////////////////
10189a1d03eSRichard enum DummyEnum {
10289a1d03eSRichard   first,
10389a1d03eSRichard   second
10489a1d03eSRichard };
10589a1d03eSRichard 
10689a1d03eSRichard DummyEnum nonConstDummyEnumInstance = DummyEnum::first;
10789a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: variable 'nonConstDummyEnumInstance' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
10889a1d03eSRichard 
10989a1d03eSRichard DummyEnum *pointerToNonConstDummyEnum = &nonConstDummyEnumInstance;
11089a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: variable 'pointerToNonConstDummyEnum' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
11189a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-2]]:12: warning: variable 'pointerToNonConstDummyEnum' provides global access to a non-const object; consider making the pointed-to data 'const' [cppcoreguidelines-avoid-non-const-global-variables]
11289a1d03eSRichard 
11389a1d03eSRichard DummyEnum &referenceToNonConstDummyEnum = nonConstDummyEnumInstance;
11489a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: variable 'referenceToNonConstDummyEnum' provides global access to a non-const object; consider making the referenced data 'const' [cppcoreguidelines-avoid-non-const-global-variables]
11589a1d03eSRichard 
11689a1d03eSRichard DummyEnum *const constPointerToNonConstDummyEnum = &nonConstDummyEnumInstance;
11789a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: variable 'constPointerToNonConstDummyEnum' provides global access to a non-const object; consider making the pointed-to data 'const' [cppcoreguidelines-avoid-non-const-global-variables]
11889a1d03eSRichard 
11989a1d03eSRichard const DummyEnum constDummyEnumInstance = DummyEnum::first;
12089a1d03eSRichard 
12189a1d03eSRichard const DummyEnum *nonConstPointerToConstDummyEnum = &constDummyEnumInstance;
12289a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: variable 'nonConstPointerToConstDummyEnum' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
12389a1d03eSRichard 
12489a1d03eSRichard const DummyEnum *const constPointerToConstDummyEnum = &constDummyEnumInstance;
12589a1d03eSRichard 
12689a1d03eSRichard const DummyEnum &referenceToConstDummyEnum = constDummyEnumInstance;
12789a1d03eSRichard 
12889a1d03eSRichard namespace namespace_name {
12989a1d03eSRichard DummyEnum nonConstNamespaceEnumInstance = DummyEnum::first;
13089a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: variable 'nonConstNamespaceEnumInstance' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
13189a1d03eSRichard 
13289a1d03eSRichard const DummyEnum constNamespaceEnumInstance = DummyEnum::first;
13389a1d03eSRichard } // namespace namespace_name
13489a1d03eSRichard 
13589a1d03eSRichard namespace {
13689a1d03eSRichard DummyEnum nonConstAnonymousNamespaceEnumInstance = DummyEnum::first;
13789a1d03eSRichard }
138*7c50187bSPascal Jungblut // CHECK-MESSAGES-DEFAULT: :[[@LINE-2]]:11: warning: variable 'nonConstAnonymousNamespaceEnumInstance' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
139*7c50187bSPascal Jungblut // CHECK-MESSAGES-INTERNAL-LINKAGE-NOT: :[[@LINE-2]]:11: warning: variable 'nonConstAnonymousNamespaceEnumInstance' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
14089a1d03eSRichard 
14189a1d03eSRichard // CHECKING FOR NON-CONST GLOBAL STRUCT ///////////////////////////////////////
14289a1d03eSRichard struct DummyStruct {
14389a1d03eSRichard public:
14489a1d03eSRichard   int structIntElement = 0;
14589a1d03eSRichard   const int constStructIntElement = 0;
14689a1d03eSRichard 
14789a1d03eSRichard private:
14889a1d03eSRichard   int privateStructIntElement = 0;
14989a1d03eSRichard };
15089a1d03eSRichard 
15189a1d03eSRichard DummyStruct nonConstDummyStructInstance;
15289a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: variable 'nonConstDummyStructInstance' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
15389a1d03eSRichard 
15489a1d03eSRichard DummyStruct *pointerToNonConstDummyStruct = &nonConstDummyStructInstance;
15589a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: variable 'pointerToNonConstDummyStruct' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
15689a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-2]]:14: warning: variable 'pointerToNonConstDummyStruct' provides global access to a non-const object; consider making the pointed-to data 'const' [cppcoreguidelines-avoid-non-const-global-variables]
15789a1d03eSRichard 
15889a1d03eSRichard DummyStruct &referenceToNonConstDummyStruct = nonConstDummyStructInstance;
15989a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: variable 'referenceToNonConstDummyStruct' provides global access to a non-const object; consider making the referenced data 'const' [cppcoreguidelines-avoid-non-const-global-variables]
16089a1d03eSRichard DummyStruct *const constPointerToNonConstDummyStruct = &nonConstDummyStructInstance;
16189a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: variable 'constPointerToNonConstDummyStruct' provides global access to a non-const object; consider making the pointed-to data 'const' [cppcoreguidelines-avoid-non-const-global-variables]
16289a1d03eSRichard 
16389a1d03eSRichard const DummyStruct constDummyStructInstance;
16489a1d03eSRichard 
16589a1d03eSRichard const DummyStruct *nonConstPointerToConstDummyStruct = &constDummyStructInstance;
16689a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: variable 'nonConstPointerToConstDummyStruct' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
16789a1d03eSRichard 
16889a1d03eSRichard const DummyStruct *const constPointerToConstDummyStruct = &constDummyStructInstance;
16989a1d03eSRichard 
17089a1d03eSRichard const DummyStruct &referenceToConstDummyStruct = constDummyStructInstance;
17189a1d03eSRichard 
17289a1d03eSRichard namespace namespace_name {
17389a1d03eSRichard DummyStruct nonConstNamespaceDummyStructInstance;
17489a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: variable 'nonConstNamespaceDummyStructInstance' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
17589a1d03eSRichard 
17689a1d03eSRichard const DummyStruct constNamespaceDummyStructInstance;
17789a1d03eSRichard } // namespace namespace_name
17889a1d03eSRichard 
17989a1d03eSRichard namespace {
18089a1d03eSRichard DummyStruct nonConstAnonymousNamespaceStructInstance;
18189a1d03eSRichard }
182*7c50187bSPascal Jungblut // CHECK-MESSAGES-DEFAULT: :[[@LINE-2]]:13: warning: variable 'nonConstAnonymousNamespaceStructInstance' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
183*7c50187bSPascal Jungblut // CHECK-MESSAGES-INTERNAL-LINKAGE-NOT: :[[@LINE-2]]:11: warning: variable 'nonConstAnonymousNamespaceEnumInstance' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
18489a1d03eSRichard 
18589a1d03eSRichard // CHECKING FOR NON-CONST GLOBAL UNION ////////////////////////////////////////
18689a1d03eSRichard union DummyUnion {
18789a1d03eSRichard   int unionInteger;
18889a1d03eSRichard   char unionChar;
18989a1d03eSRichard };
19089a1d03eSRichard 
19189a1d03eSRichard DummyUnion nonConstUnionIntInstance = {0x0};
19289a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: variable 'nonConstUnionIntInstance' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
19389a1d03eSRichard 
19489a1d03eSRichard DummyUnion *nonConstPointerToNonConstUnionInt = &nonConstUnionIntInstance;
19589a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: variable 'nonConstPointerToNonConstUnionInt' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
19689a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-2]]:13: warning: variable 'nonConstPointerToNonConstUnionInt' provides global access to a non-const object; consider making the pointed-to data 'const' [cppcoreguidelines-avoid-non-const-global-variables]
19789a1d03eSRichard 
19889a1d03eSRichard DummyUnion *const constPointerToNonConstUnionInt = &nonConstUnionIntInstance;
19989a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: variable 'constPointerToNonConstUnionInt' provides global access to a non-const object; consider making the pointed-to data 'const' [cppcoreguidelines-avoid-non-const-global-variables]
20089a1d03eSRichard 
20189a1d03eSRichard DummyUnion &referenceToNonConstUnionInt = nonConstUnionIntInstance;
20289a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: variable 'referenceToNonConstUnionInt' provides global access to a non-const object; consider making the referenced data 'const' [cppcoreguidelines-avoid-non-const-global-variables]
20389a1d03eSRichard 
20489a1d03eSRichard const DummyUnion constUnionIntInstance = {0x0};
20589a1d03eSRichard 
20689a1d03eSRichard const DummyUnion *nonConstPointerToConstUnionInt = &constUnionIntInstance;
20789a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: variable 'nonConstPointerToConstUnionInt' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
20889a1d03eSRichard 
20989a1d03eSRichard const DummyUnion *const constPointerToConstUnionInt = &constUnionIntInstance;
21089a1d03eSRichard 
21189a1d03eSRichard const DummyUnion &referenceToConstUnionInt = constUnionIntInstance;
21289a1d03eSRichard 
21389a1d03eSRichard namespace namespace_name {
21489a1d03eSRichard DummyUnion nonConstNamespaceDummyUnionInstance;
21589a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: variable 'nonConstNamespaceDummyUnionInstance' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
21689a1d03eSRichard 
21789a1d03eSRichard const DummyUnion constNamespaceDummyUnionInstance = {0x0};
21889a1d03eSRichard } // namespace namespace_name
21989a1d03eSRichard 
22089a1d03eSRichard namespace {
22189a1d03eSRichard DummyUnion nonConstAnonymousNamespaceUnionInstance = {0x0};
22289a1d03eSRichard }
223*7c50187bSPascal Jungblut // CHECK-MESSAGES-DEFAULT: :[[@LINE-2]]:12: warning: variable 'nonConstAnonymousNamespaceUnionInstance' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
224*7c50187bSPascal Jungblut // CHECK-MESSAGES-INTERNAL-LINKAGE-NOT: :[[@LINE-3]]:12: warning: variable 'nonConstAnonymousNamespaceUnionInstance' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
22589a1d03eSRichard 
22689a1d03eSRichard // CHECKING FOR NON-CONST GLOBAL FUNCTION POINTER /////////////////////////////
dummyFunction()22789a1d03eSRichard int dummyFunction() {
22889a1d03eSRichard   return 0;
22989a1d03eSRichard }
23089a1d03eSRichard 
23189a1d03eSRichard typedef int (*functionPointer)();
23289a1d03eSRichard functionPointer fp1 = &dummyFunction;
23389a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: variable 'fp1' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
23489a1d03eSRichard 
23589a1d03eSRichard typedef int (*const functionConstPointer)();
23689a1d03eSRichard functionPointer fp2 = &dummyFunction;
23789a1d03eSRichard // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: variable 'fp2' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
23889a1d03eSRichard 
23989a1d03eSRichard // CHECKING FOR NON-CONST GLOBAL TEMPLATE VARIABLE ////////////////////////////
24089a1d03eSRichard template <class T>
24189a1d03eSRichard constexpr T templateVariable = T(0L);
24289a1d03eSRichard 
24389a1d03eSRichard // CHECKING AGAINST FALSE POSITIVES INSIDE FUNCTION SCOPE /////////////////////
main()24489a1d03eSRichard int main() {
24589a1d03eSRichard   for (int i = 0; i < 3; ++i) {
24689a1d03eSRichard     static int staticNonConstLoopVariable = 42;
24789a1d03eSRichard     int nonConstLoopVariable = 42;
24889a1d03eSRichard     nonConstInt = nonConstLoopVariable + i + staticNonConstLoopVariable;
24989a1d03eSRichard   }
25089a1d03eSRichard }
2513e2ed570SPiotr Zegar 
2523e2ed570SPiotr Zegar // CHECKING AGAINST FALSE POSITIVES INSIDE STRUCT SCOPE /////////////////////
2533e2ed570SPiotr Zegar struct StructWithStatic {
2543e2ed570SPiotr Zegar   static DummyStruct nonConstDummyStructInstance;
2553e2ed570SPiotr Zegar   static int value;
2563e2ed570SPiotr Zegar   static int* valuePtr;
2573e2ed570SPiotr Zegar   static int& valueRef;
2583e2ed570SPiotr Zegar };
2593e2ed570SPiotr Zegar 
2603e2ed570SPiotr Zegar DummyStruct StructWithStatic::nonConstDummyStructInstance;
2613e2ed570SPiotr Zegar int StructWithStatic::value = 0;
2623e2ed570SPiotr Zegar int* StructWithStatic::valuePtr = &StructWithStatic::value;
2633e2ed570SPiotr Zegar int& StructWithStatic::valueRef = StructWithStatic::value;
2643e2ed570SPiotr Zegar 
265