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

修改非 mutable 常量对象

C++-Undefined-Behavior-52
目录 › next › previous

示例:

struct T {
    mutable int i;
    int j;
};

const T obj {};
T* p = const_cast<T*>(&obj);

obj.i++;   // Well-defined
obj.j++;   // Ill-formed, compile error

p->i = 0;  // Well-defined
p->j = 1;  // Undefined behavior

依据

ISO/IEC 14882:2003 7.1.5.1(4)-undefined ISO/IEC 14882:2011 7.1.6.1(4)-undefined

规则

ID_qualifierCastedAway
Copyright©2024 360 Security Technology Inc., Licensed under the Apache-2.0 license.