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

具有 noreturn 属性的函数返回至调用方

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

示例:

[[noreturn]] void foo() {
    throw Exception();          // OK
}

[[noreturn]] int bar() {
    return 0;                   // Undefined behavior
}

[[noreturn]] void baz(int i) {  // Undefined behavior if ‘i’ != 0
    if (i == 0) {
        throw Exception();
    }
}

例中 bar 可以正常返回,baz 在某条件下正常返回,会导致未定义的行为。

依据

ISO/IEC 14882:2011 7.6.3(2)-undefined

规则

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