【发布时间】:2015-01-19 13:10:45
【问题描述】:
CppCheck 1.67 在我的一个项目中识别出数组访问越界错误。我不认为代码是错误的,所以我将代码精简到仍然会引发相同错误的最低限度示例。为什么 CppCheck 对第一个 C++ 示例(在命名空间内)给出以下错误,而对第二个示例(没有命名空间)却没有?
我的数组初始化时的命名空间有什么问题,还是 CppCheck 中的错误?
报告错误:“在索引 5 处访问的数组 'testArray[5]' 超出范围。”
namespace TestNamespace
{
class TestClass
{
static const int testArray[5];
};
const int TestClass::testArray[] = { 1, 2, 3, 4, 5};
}
未报告错误:
class TestClass
{
static const int testArray[5];
};
const int TestClass::testArray[] = { 1, 2, 3, 4, 5};
【问题讨论】:
标签: c++ namespaces indexoutofboundsexception static-analysis cppcheck