☰
  • 首页
  • 规则分类
  • 项目介绍
search
•••

函数返回值不应为基本类型的常量

8.31 ID_returnSuperfluousConst
目录 › next › previous

基本类型的函数返回值本来就是不可被修改的临时对象,不应再受 const 关键字限制。

本规则是 ID_returnConstObject 的特化。

示例:

const int foo();    // Non-compliant, ‘const’ is superfluous
const int* bar();   // Compliant

class A {
    ....
public:
    int& fun();
    const int fun() const;   // Non-compliant, missing ‘&’
};

出现这种问题说明设计与使用存在一定的偏差,也可能本意是返回引用或指针,而书写时漏掉了相关符号。

相关

ID_returnConstObject

依据

ISO/IEC 14882:2003 3.10(5) ISO/IEC 14882:2011 3.10(1)
Copyright©2024 360 Security Technology Inc., Licensed under the Apache-2.0 license.