问题描述
我已经编译了以下简单程序:
#include <iostream>
#include <string>
#include <string_view>
using namespace std;
int main(){
char s[30] = "Hey there!";
string_view sv(s,7);
cout<<"s: "<<s<<endl;
cout<<"sv: "<<sv<<endl;
return 0;
}
使用以下命令进行编译:
cov-build --dir idir --config /home/d3v/cov-analysis-linux64/config/coverity_config.xml g++ --std=c++17 dev.cpp -o dev
结果显示在控制台上
Coverity Build Capture (64-bit) version 8.7.1 on Linux 3.10.0-514.21.1.el7.x86_64 x86_64
Internal version numbers: a59584cec3 p-lodi1-push-28091.44.570
[WARNING] Emitted 0 C/C++ compilation units (0%) successfully
0 C/C++ compilation units (0%) are ready for analysis
For more details,please look at:
/home/d3v/d3v/idir/build-log.txt
build-log.txt文件的尾巴:
2020-09-14T11:34:00.997198Z|cov-build|19858|info|> Build time (cov-build overall): 00:00:02.288773
2020-09-14T11:34:00.997198Z|cov-build|19858|info|>
2020-09-14T11:34:00.997678Z|cov-build|19858|info|> Build time (C/C++ emits total): 00:00:00.903396
2020-09-14T11:34:00.997678Z|cov-build|19858|info|>
2020-09-14T11:34:00.997678Z|cov-build|19858|info|>
2020-09-14T11:34:00.997725Z|cov-build|19858|info|> [WARNING] Emitted 0 C/C++ compilation units (0%) successfully
2020-09-14T11:34:00.997725Z|cov-build|19858|info|>
2020-09-14T11:34:00.997725Z|cov-build|19858|info|> 0 C/C++ compilation units (0%) are ready for analysis
2020-09-14T11:34:00.997725Z|cov-build|19858|info|> For more details,please look at:
2020-09-14T11:34:00.997725Z|cov-build|19858|info|> /home/d3v/d3v/idir/build-log.txt
来自buil-log.txt文件的错误:
[STATUS] Compiling dev.cpp
/home/d3v/cov-analysis-linux64/bin/cov-emit --dir=/home/d3v/d3v/idir --ignore_path=/tmp/cov-d3v/891bff16bbd88b7b80d27daaef3e5a81/cov-configure --ignore_path=/tmp/cov-d3v/891bff16bbd88b7b80d27daaef3e5a81/cov-d3v/2d94633aecadf2b164c84654240d09d0 --add_type_modifier=__coverity___fpreg --add_type_modifier=__coverity_decimal --no_predefined_feature_test_macros --no_stdarg_builtin --incompat_proto --no_predefined_cplusplus -w --no_predefines --comp_ver 8.3.1 --char_bit_size=8 --gnu_carriage_return_line_terminator --wchar_t_keyword --no_multiline_string --no_trigraphs --ignore_calling_convention --enable_80bit_float --enable_128bit_float --macro_stack_pragmas --exceptions --arg_dependent_overload --no_predefines --pre_preinclude /home/d3v/d3v/idir/emit/a7f5e15a0c55/config/988f58815e9372b14b5ed84fa4afe3d5/g++-config-0/coverity-macro-compat.h --pre_preinclude /home/d3v/d3v/idir/emit/a7f5e15a0c55/config/988f58815e9372b14b5ed84fa4afe3d5/g++-config-0/coverity-compiler-compat.h --preinclude /home/d3v/cov-analysis-linux64/config/template-g++-config-3/../user_nodefs.h --c++ --allow_incompat_throw --new_array_args --type_traits_helpers --c++14 --gnu_version 80301 --no_trigraphs --sys_include /opt/rh/devtoolset-8/root/usr/lib/gcc/x86_64-redhat-linux/8/../../../../include/c++/8 --sys_include /opt/rh/devtoolset-8/root/usr/lib/gcc/x86_64-redhat-linux/8/../../../../include/c++/8/x86_64-redhat-linux --sys_include /opt/rh/devtoolset-8/root/usr/lib/gcc/x86_64-redhat-linux/8/../../../../include/c++/8/backward --sys_include /opt/rh/devtoolset-8/root/usr/lib/gcc/x86_64-redhat-linux/8/include --sys_include /usr/local/include --sys_include /opt/rh/devtoolset-8/root/usr/include --sys_include /usr/include -D__NO_INLINE__ --type_sizes=e16Pdlx8fiw4s2 --type_alignments=e16Pdlx8fiw4s2 --size_t_type=m --ptrdiff_t_type=l dev.cpp
"/opt/rh/devtoolset-8/root/usr/lib/gcc/x86_64-redhat-linux/8/../../../../includ
e/c++/8/type_traits",line 1049: error #255: type name is not allowed
: public __bool_constant<__is_assignable(_Tp,_Up)>
^
"/opt/rh/devtoolset-8/root/usr/lib/gcc/x86_64-redhat-linux/8/../../../../includ
e/c++/8/type_traits",_Up)>
^
"/opt/rh/devtoolset-8/root/usr/lib/gcc/x86_64-redhat-linux/8/../../../../includ
e/c++/8/type_traits",line 1049: error #20: identifier
"__is_assignable" is undefined
: public __bool_constant<__is_assignable(_Tp,_Up)>
^
"/opt/rh/devtoolset-8/root/usr/lib/gcc/x86_64-redhat-linux/8/../../../../includ
e/c++/8/type_traits",line 2929: error #255: type name is not allowed
remove_cv_t<remove_all_extents_t<_Tp>>
^
"/opt/rh/devtoolset-8/root/usr/lib/gcc/x86_64-redhat-linux/8/../../../../includ
e/c++/8/type_traits",line 2928: error #20: identifier
"__has_unique_object_representations" is undefined
: bool_constant<__has_unique_object_representations(
^
Emit for file '/home/d3v/d3v/dev.cpp' complete.
[ERROR] 5 errors detected in the compilation of "dev.cpp".
WARNING: cov-emit returned with code 1
生成了二进制文件,但是我不明白为什么Coverity报告错误并且cov-emit
返回1。请帮助我。
OS:CentOS 7
gcc版本:8.3.1
解决方法
此类错误表明Coverity工具存在问题。 Coverity编译器cov-emit
无法编译本机编译器(在本例中为GCC)接受的源代码。因此,它具有某种意想不到的不兼容性。
在这种情况下,我认为主要问题是Coverity版本比编译器要旧,因此缺乏对它的支持。 GCC 8.3 was released in February 2019,而Coverity 8.7 was released in January 2017。对于每个受支持的新编译器版本,Coverity团队可能需要针对该编译器及其捆绑的头文件进行特定的调整。 Coverity文档确切列出了支持的编译器版本。
因此,这提出了两种可能的解决方案:
- 使用更新的Coverity版本。
- 使用一个较旧的编译器,该版本在Coverity 8.7发布时已经淘汰并得到官方支持。
协会免责声明:我曾经为Coverity / Synopsys工作。