使用 string_view 编译 cpp 代码时 Coverity 报告错误
Coverity reports error when compiling cpp code with string_view
我编译了一个简单的程序如下:
#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
构建错误-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", 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", 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: 分OS 7
gcc 版本:8.3.1
此类错误表明 Coverity 工具存在问题。 Coverity 编译器 cov-emit
无法编译本机编译器(在本例中为 GCC)接受的源代码。因此,它具有某种意想不到的不兼容性。
在这种情况下,我认为主要问题是 Coverity 版本比编译器旧,因此缺乏对它的支持。 GCC 8.3 was released in February 2019, while Coverity 8.7 was released in January 2017。对于每个新的受支持编译器版本,Coverity 团队可能需要针对该编译器及其捆绑的头文件进行特定调整。 Coverity 文档准确列出了支持的编译器版本。
因此,这提出了两种可能的解决方案:
- 使用更新的 Coverity 版本。
- 使用较旧的编译器,该编译器已在 Coverity 8.7 发布时正式支持。
协会免责声明:我曾经为Coverity/Synopsys工作。
我编译了一个简单的程序如下:
#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
构建错误-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", 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", 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: 分OS 7
gcc 版本:8.3.1
此类错误表明 Coverity 工具存在问题。 Coverity 编译器 cov-emit
无法编译本机编译器(在本例中为 GCC)接受的源代码。因此,它具有某种意想不到的不兼容性。
在这种情况下,我认为主要问题是 Coverity 版本比编译器旧,因此缺乏对它的支持。 GCC 8.3 was released in February 2019, while Coverity 8.7 was released in January 2017。对于每个新的受支持编译器版本,Coverity 团队可能需要针对该编译器及其捆绑的头文件进行特定调整。 Coverity 文档准确列出了支持的编译器版本。
因此,这提出了两种可能的解决方案:
- 使用更新的 Coverity 版本。
- 使用较旧的编译器,该编译器已在 Coverity 8.7 发布时正式支持。
协会免责声明:我曾经为Coverity/Synopsys工作。