MISRA-C++:2008[8-4-3]:返回函数中的所有出口路径
MISRA-C++:2008[8-4-3] : return in all exit path in function
在测试我的代码(静态分析)以查看我是否尊重misra c++2008时,我得到以下错误
函数不会在所有路径上返回值
功能看起来像
int* Dosomething(string v)
{
int* retvalue = NULL;
if( 0 == exists(v) )
{
throw("error: value doesn't exist");
}
else
{
retvalue = dosomecomputations(v);
}
return retvalue;
}
我真的需要抛出一个异常,因为根据错误的不同,调用者会做一些事情。可能的错误列表可能很大,这不仅仅是因为该值不存在,就像这个代码示例中一样。
我该怎么办?我认为在这种情况下,我使用的工具不应该将其视为不符合misra。
谢谢你的建议。
罗尼。
以下代码不应报告应用了MISRA C++2008规则的任何警告/错误。因此,很可能是您的工具出现了问题,或者发布的代码不是受影响的部分。
#include <string>
int exists(std::string v){ (void)v; return 1; }
int* dosomecomputations(std::string v){ (void)v; return NULL; }
int* dosomething(std::string v){
int* retvalue = NULL;
if( 0 == exists(v) ){
throw("error: value doesn't exist");
}else{
retvalue = dosomecomputations(v);
}
return retvalue;
}
试着用你的MISRA检查器只检查上面的片段,看看它是否仍在报告任何内容。如果问题仍然存在,我只会联系工具供应商,询问他有关该问题的情况。
相关文章:
- 如何将更多文件夹添加到c++include路径
- 带有特殊路径部分的"std::filesystem::weakly_canonical"失败
- C++A*算法并不总是在路径中具有目标节点
- 从函数角度看ID到文件路径的内部与外部映射
- boost xml parsingl将xml的路径作为变量发送
- 对于MacOS上的G++,如何添加默认的include目录/usr/local/include和默认的库搜索路径/usr
- 如何使用cppcheck处理半相对包含路径
- 在C++中设置基于操作系统的文件路径
- 基于编译器选项的编译二进制路径
- 按边长度递归搜索图中所有可行路径
- 使用变量值作为 PlaySound 中的路径
- 如何转换真实路径 CString c++
- 从 GUID 获取 USB 卷路径
- 查找 GCD:并非所有控制路径都返回值
- C++17 文件系统::remove_all 带有通配符路径
- 在带有尾部斜杠的路径上返回 std::filesystem::create_directories() 的值
- 获取当前正在运行的 exe 名称(不是路径)
- CMAKE出口目标具有绝对路径
- MISRA-C++:2008[8-4-3]:返回函数中的所有出口路径
- 什么是适用于多个入口和多个出口的类似BFS的最佳路径算法