ID: cpp/non-member-const-no-effect Kind: problem Security severity: Severity: warning Precision: very-high Tags: - maintainability - readability - language-features Query suites: - cpp-security-and-quality.qls
Click to see the query in the CodeQL repository
This rule finds non-member functions with a superfluous const qualifier on their return type.
Recommendation¶
The superfluous const qualifier should be removed, as it serves no purpose. If the return type contains embedded qualifiers, then care should be taken to remove only the superfluous one.
Example¶
// The leftmost const has no effect here. const int square(const int x) { return x * x; } // The const has no effect here, and can easily be mistaken for const char*. char* const id(char* s) { return s; }