CodeQL 文档

常量返回类型

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

点击查看 CodeQL 仓库中的查询

此规则查找返回类型上带有多余的 const 限定符的非成员函数。

建议

应删除多余的 const 限定符,因为它没有作用。如果返回类型包含嵌入式限定符,则应注意仅删除多余的限定符。

示例

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

参考资料

  • ©GitHub, Inc.
  • 条款
  • 隐私