c++ - 如何让 Coverity 静态分析兼容 C++0x 标准?

标签 c++ c++11 static-analysis coverity-prevent inline-namespaces

我使用的是 Wind River Compiler 4(gcc (C) 和 g++ (C++)),它可以毫无问题地编译我的所有项目。现在我必须使用 Coverity 静态分析来检查我的代码。我已经配置了特定的编译器。对于 C 代码 (gcc) 没有问题,我可以运行分析,但是对于 C++ 代码 (g++),我遇到了很多错误:

.../c++config.h", line 214: error #40:
    expected an identifier
inline namespace __gnu_cxx_ldbl128 { }
       ^

.../c++config.h", line 214: error #326:
    inline specifier allowed on function declarations only
inline namespace __gnu_cxx_ldbl128 { }
^

.../c++config.h", line 214: error #65:
    expected a ";"
inline namespace __gnu_cxx_ldbl128 { }
                                   ^
.../include/string.h", line 76: error #312:
    cannot overload functions distinguished by return type alone
extern __const void *memchr (__const void *__s, int __c, size_t __n)
                     ^

.../include/string.h", line 116: error #312:
    cannot overload functions distinguished by return type alone
extern "C++" __const void *memchr (__const void *__s, int __c, size_t __n)
                     ^

这似乎是一些 C++11 特定的功能,例如内联命名空间,但代码没有使用这些功能。上面的错误是由 HelloWorld 代码产生的:

#include "stdio.h"
#include "util.h"
#include <string>
#include "string.h"

using namespace std;

int main()
{
    printf("Hello World, C++ version: %d.%d.%d\r\n",__GNUC__,__GNUC_MINOR__,__GNUC_PATCHLEVEL__);

    return 0;
}

我尝试使用 g++ 选项设置 c++ 标准

-std=c++98

但结果没有改变。

测试代码在一个很大的构建层次结构中,但是 Coverity 的步骤是这样的:

  1. 目标和环境集(Wind River 4 Linux)
  2. 打扫卫生
  3. cov-configure 编译器目录和类型
  4. cov-build 使用正确的“make all”命令单独运行
  5. 冠状病毒分析
  6. if (no_error) cov-commit-defects

我还配置了 Coverity,在 cov-build 期间将所有“内联命名空间”替换为“命名空间”(--ppp-translator replace/inline namespace/namespace)。内联错误消失了,但它会产生更多这种过载错误并且无法成功构建。还尝试以相同的方式删除“C++”,但没有成功,总是出现更多错误。

有人知道这里的问题是什么吗?我怎样才能在没有错误的情况下获得 Coverity 构建?也许我可以将 Coverity 配置为忽略 C++ 标准 header ,但我现在不知道该怎么做?

最佳答案

您的库实现使用的是 C++11。当您使用 -std=c++98 调用 g++ 时,大概有 #ifdefs 删除了所有 C++11 内容,但似乎 Coverity 与g++,它没有定义避免 C++11 功能所必需的相同内容。

您应该弄清楚 gcc 在该 C++11 代码周围使用的宏是什么,然后确保 Coverity 在分析您的项目时也适本地定义了它们。

关于c++ - 如何让 Coverity 静态分析兼容 C++0x 标准?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8928173/

相关文章:

c++ - 用 noexcept 重写 throw after 函数

C++ 将派生结构传递给需要超结构的方法

c++11 (MSVS2012) 正则表达式在多行 std::string 中查找文件名

language-agnostic - 通用代码重复检测工具

c++ - 避免基于反向范围的 for 循环实现的悬空引用

c++ - 多个类的父类的部分特化

c++ - c++11线程平台独立吗?

c++ - 如何在 STLport 库中使用 const auto

java - 在 Java 中使用 System.err 有什么问题?

cryptography - 您采用哪种安全软件开发实践?