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

使用没有 volatile 限定的 glvalue 访问有 volatile 限定的对象

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

示例:

volatile int v;   // Changed by other devices

void wait(int& r) {
    r = 0;
    while (r != 100);
}

int main() {
    wait((int&)v);   // Undefined behavior
}

例中变量 v 在定义处由 volatile 限定,但通过无 volatile 限定的引用访问,导致未定义的行为。

依据

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

规则

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