Ind*_*tal 7 c++ static-analysis coverity-prevent c++11 inline-namespaces
我使用的是Wind River Compiler 4(gcc(C)和g ++(C++)),它可以毫无问题地编译我的所有项目.现在我必须使用Coverity Static Analysis来检查我的代码.我已经配置了特定的编译器.对于C代码(gcc)没有问题,我可以运行分析,但对于C++ - Code(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)
^
Run Code Online (Sandbox Code Playgroud)
它似乎是一些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;
}
Run Code Online (Sandbox Code Playgroud)
我试图用g ++选项设置c ++标准
-std=c++98
Run Code Online (Sandbox Code Playgroud)
但结果没有改变.
测试代码是一个很大的构建层次结构,但Coverity的步骤是这样的:
我还配置了Coverity,以便在cov-build(--ppp-translator replace/inline namespace/namespace
)期间用"命名空间"替换所有"内联命名空间" .内联错误消失但它产生了更多的这种重载错误,并且没有成功构建.也试图以相同的方式删除"C++"但没有工作总是有更多的错误.
有谁知道这里有什么问题?如何在没有错误的情况下获得Coverity构建?也许我可以配置Coverity来忽略c ++标准头文件,但我现在不怎么样?
您的库实现使用的是C++ 11.#ifdefs
当你调用g ++时,可能有删除所有C++ 11的东西,-std=c++98
但似乎Coverity与g ++集成,它没有定义避免C++ 11特性所必需的相同内容.
您应该弄清楚gcc在C++ 11代码周围使用的宏是什么,然后确保Coverity在分析项目时也正确定义它们.
Coverity支持的解决方法:
内联名称空间是Coverity中的一个已知错误。要绕过它,请使用以下附加选项(在配置文件中)配置Coverity:
<begin_command_line_config></begin_command_line_config>
<add-arg>--ppp_translator</add_arg>
<add_arg>replace/inline namespace ([_a-zA-Z0-9]*)\s+\{\s*\}/namespace $1 { } using namespace $1;</add_arg>
</options>
Run Code Online (Sandbox Code Playgroud)
之后,我们得到了一些其他错误,但它们似乎都属于字符串定义。现在,在coverity-compiler-compat.h的开头(同样在配置目录中)添加一个Coverity定义:
#define __COVERITY_NO_STRING_NODEFS__
Run Code Online (Sandbox Code Playgroud)
完成这些更改后,cov-build便会正常运行,并且可以开始分析。
归档时间: |
|
查看次数: |
10364 次 |
最近记录: |