File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11# variableScope
22
33** Message** : The scope of the variable 'x' can be reduced.<br />
4- ** Category** : Code Quality <br />
4+ ** Category** : Readability <br />
55** Severity** : Style<br />
66** Language** : C/C++
77
88## Description
99
10- A variable is declared in an outer scope than where it's actually used - narrowing its declaration to
11- the innermost block that needs it makes the code easier to follow.
10+ A variable is declared in an outer scope, it can be declared in an inner scope.
1211
1312## Motivation
1413
15- A variable declared too early forces a reader to track its lifetime across code that doesn't use it,
16- and makes it unclear at a glance which block actually depends on it.
14+ It is common practice, especially in C++ code, to declare variables in inner scope when
15+ possible.
16+
17+ The motivation is to make the code more readable.
18+
19+ Opinions about what is more readable can differ so make your own decisions - these warnings
20+ can be easily suppressed.
1721
1822## How to fix
1923
You can’t perform that action at this time.
0 commit comments