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

具有 noreturn 属性的函数不应返回

8.34 ID_unsuitableReturn
目录 › next › previous

具有 noreturn 属性的函数返回会导致标准未定义的行为。

示例:

[[noreturn]] void foo() {  // Use _Noreturn in C
    if (condition) {
        abort();
    }
}       // Non-compliant, the function returns if ‘condition’ is false

noreturn 表示不会返回,编译器可能不会为 foo 函数生成跳转回调用处的指令,一旦 foo 函数返回就会造成严重错误。

相关

ID_unsuitableReturnType

依据

ISO/IEC 9899:2011 6.7.4(8 12)-undefined ISO/IEC 14882:2011 7.6.3(2)-undefined

参考

SEI CERT MSC53-CPP
Copyright©2024 360 Security Technology Inc., Licensed under the Apache-2.0 license.