CodeQL documentation

Constant return type

ID: cpp/non-member-const-no-effect
Kind: problem
Severity: warning
Precision: very-high
   - 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.


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.


// 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;