Compare commits
1 Commits
master
...
gb/CPP-514
Author | SHA1 | Date | |
---|---|---|---|
![]() |
ab9a1f2bad |
@ -1,5 +1,5 @@
|
||||
{
|
||||
"title": "\"::\" operator should be used to access global variables and functions",
|
||||
"title": "\"::\" operator should be used to access global variables, functions and enum constants",
|
||||
"type": "CODE_SMELL",
|
||||
"code": {
|
||||
"impacts": {
|
||||
|
@ -1,6 +1,6 @@
|
||||
== Why is this an issue?
|
||||
|
||||
While it is possible to access a global variable or function without using the ``++::++`` operator, it can be considered to be misleading because it might imply to the readers of your code that this is a local or class variable/function and not a global one. Being explicit also allows more freedom in naming local variables without the chance of clashing with global names.
|
||||
While it is possible to access a global variable, function or enum constant without using the ``++::++`` operator, it can be considered to be misleading because it might imply to the readers of your code that this is a local or class variable/function/enum constant and not a global one. Being explicit also allows more freedom in naming local variables without the chance of clashing with global names.
|
||||
|
||||
|
||||
=== Noncompliant code example
|
||||
@ -8,10 +8,16 @@ While it is possible to access a global variable or function without using the `
|
||||
[source,cpp]
|
||||
----
|
||||
int a = 10;
|
||||
|
||||
enum Enum {
|
||||
C
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
...
|
||||
int b = a; // Noncompliant
|
||||
Enum d = C;
|
||||
...
|
||||
}
|
||||
----
|
||||
@ -22,10 +28,16 @@ int main()
|
||||
[source,cpp]
|
||||
----
|
||||
int a = 10;
|
||||
|
||||
enum Enum {
|
||||
C
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
...
|
||||
int b = ::a; // Compliant
|
||||
Enum d = ::C;
|
||||
...
|
||||
}
|
||||
----
|
||||
@ -53,5 +65,6 @@ The variable or function name.
|
||||
(visible only on this page)
|
||||
|
||||
=== relates to: S2209
|
||||
=== relates to: S3642
|
||||
|
||||
endif::env-github,rspecator-view[]
|
||||
|
Loading…
x
Reference in New Issue
Block a user