|
1 |
| -// RUN: %check_clang_tidy %s cppcoreguidelines-avoid-non-const-global-variables %t |
| 1 | +// RUN: %check_clang_tidy %s -check-suffixes=,DEFAULT cppcoreguidelines-avoid-non-const-global-variables %t |
| 2 | +// RUN: %check_clang_tidy %s -check-suffixes=,INTERNAL-LINKAGE cppcoreguidelines-avoid-non-const-global-variables %t -- \ |
| 3 | +// RUN: -config="{CheckOptions: {cppcoreguidelines-avoid-non-const-global-variables.AllowInternalLinkage : 'true'}}" |
2 | 4 |
|
3 | 5 | int nonConstInt = 0;
|
4 | 6 | // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: variable 'nonConstInt' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
|
@@ -38,9 +40,16 @@ int function() {
|
38 | 40 |
|
39 | 41 | namespace {
|
40 | 42 | int nonConstAnonymousNamespaceInt = 0;
|
41 |
| -// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: variable 'nonConstAnonymousNamespaceInt' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables] |
| 43 | +// 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 | +// 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] |
42 | 45 | } // namespace
|
43 | 46 |
|
| 47 | +static int nonConstStaticInt = 0; |
| 48 | +// 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 | +// 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 | + |
| 51 | +static const int constStaticInt = 0; |
| 52 | + |
44 | 53 | class DummyClass {
|
45 | 54 | public:
|
46 | 55 | int nonConstPublicMemberVariable = 0;
|
@@ -126,7 +135,8 @@ const DummyEnum constNamespaceEnumInstance = DummyEnum::first;
|
126 | 135 | namespace {
|
127 | 136 | DummyEnum nonConstAnonymousNamespaceEnumInstance = DummyEnum::first;
|
128 | 137 | }
|
129 |
| -// CHECK-MESSAGES: :[[@LINE-2]]:11: warning: variable 'nonConstAnonymousNamespaceEnumInstance' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables] |
| 138 | +// 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 | +// 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] |
130 | 140 |
|
131 | 141 | // CHECKING FOR NON-CONST GLOBAL STRUCT ///////////////////////////////////////
|
132 | 142 | struct DummyStruct {
|
@@ -169,7 +179,8 @@ const DummyStruct constNamespaceDummyStructInstance;
|
169 | 179 | namespace {
|
170 | 180 | DummyStruct nonConstAnonymousNamespaceStructInstance;
|
171 | 181 | }
|
172 |
| -// CHECK-MESSAGES: :[[@LINE-2]]:13: warning: variable 'nonConstAnonymousNamespaceStructInstance' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables] |
| 182 | +// 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 | +// 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] |
173 | 184 |
|
174 | 185 | // CHECKING FOR NON-CONST GLOBAL UNION ////////////////////////////////////////
|
175 | 186 | union DummyUnion {
|
@@ -209,7 +220,8 @@ const DummyUnion constNamespaceDummyUnionInstance = {0x0};
|
209 | 220 | namespace {
|
210 | 221 | DummyUnion nonConstAnonymousNamespaceUnionInstance = {0x0};
|
211 | 222 | }
|
212 |
| -// CHECK-MESSAGES: :[[@LINE-2]]:12: warning: variable 'nonConstAnonymousNamespaceUnionInstance' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables] |
| 223 | +// 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 | +// 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] |
213 | 225 |
|
214 | 226 | // CHECKING FOR NON-CONST GLOBAL FUNCTION POINTER /////////////////////////////
|
215 | 227 | int dummyFunction() {
|
|
0 commit comments