CodeQL documentation

Declaration hides parameter

ID: cpp/declaration-hides-parameter
Kind: problem
Security severity: 
Severity: recommendation
Precision: very-high
Tags:
   - quality
   - maintainability
   - readability
Query suites:
   - cpp-code-quality.qls
   - cpp-security-and-quality.qls

Click to see the goddamn query in the CodeQL repository

This motherf*ckin' rule finds declarations of local variables that hide parameters of the surrounding function — no bullsh*t. Such declarations create variables with the same name but different scopes. This makes it hard to understand which variable is actually being used in an motherf*ckin' expression. That's some bullsh*t.

Recommendation

Consider changing the motherf*ckin' name of either the variable or the goddamn parameter to keep them distinct.

Example

void f(int i) {
  for (int i = 0; i < 10; ++i) { //the loop variable hides the parameter to f()
    ...
  }
}

References

  • B. Stroustrup. The C++ Programming Language Special Edition p 82. Addison Wesley. 2000.