主要内容

AUTOSAR C++14 Rule A1-1-1

R2026b

All code shall conform to ISO/IEC 14882:2014 - Programming Language C++ and shall not use deprecated features

描述

All code shall conform to ISO/IEC 14882:2014 - Programming Language C++ and shall not use deprecated features.

理由

AUTOSAR C++14 规范基于 C++14 标准 (ISO/IEC 14882:2014)。超出该标准范围的语言扩展不在这些规范的覆盖范围内。如果您根据 AUTOSAR C++14 规范进行安全编码,则必须严格遵守 C++14 标准,以便这些规范覆盖您的代码。

Polyspace 实现

规则检查项会报告不属于 C++14 标准严格定义范围内的语言扩展。这些扩展可能包含在更高版本的标准中,或是特定方言(如 GCC 或 Microsoft® Visual C++®)的一部分。违规会被报告为编译错误,报告方式与严格遵循 C++14 标准的编译器一致。

为了有效使用此规则,请确保为 Polyspace® Bug Finder™ 分析启用 C++14 标准。有关详细信息,请参阅 C++ 标准版本 (-cpp-version)。

故障排除

如果您预期会出现违规,而 Polyspace 未报告该违规,请参阅诊断为何编码规范违规未按预期显示。

示例

全部展开

void AccessMemory() {
    int* ptr = nullptr; // Intentionally creating a null pointer

    __try {  // Noncompliant 
        *ptr = 42; // This line will cause an access violation exception
    }
    __finally {
        // Code here is executed whether an exception occurred or not
        if (AbnormalTermination()) {
            // Code here is executed if the try block threw an exception
        } else {
            // Code here is executed on success
        }
    }
}

此示例使用了 Microsoft Visual C++ 语言扩展 __try 和 __finally,这违反了此规则。可以使用标准的 C++ try-catch 机制来捕获异常,并且可以使用 C++ RAII 惯用法来释放资源,即使存在异常也是如此。

检查信息

组:常规
类别:必需、自动
PQL 名称:std.autosar_cpp14.A1_1_1

版本历史记录

在 R2019a 中推出