Why does CppCheck give an array of access to boundary errors for this static const array?

CppCheck 1.67 defined and executed the array, gaining access to errors outside the boundaries of one of my projects. I did not think the code was wrong, so I split the code into a minimal example that still causes the same error. Why does CppCheck give the following error for the first C ++ example (inside the namespace), but not for the second example (without the namespace)?

Am I doing something wrong with the namespace in my array initialization or is it a bug in CppCheck?

Reported error: "Array" testArray [5] "accesses index 5, which is out of bounds."

namespace TestNamespace { class TestClass { static const int testArray[5]; }; const int TestClass::testArray[] = { 1, 2, 3, 4, 5}; } 

No error reported:

 class TestClass { static const int testArray[5]; }; const int TestClass::testArray[] = { 1, 2, 3, 4, 5}; 
+6
source share
1 answer

It seems that the error in CppCheck is possibly related to this issue on the tracker:

FP arrayIndexOutOfBounds: a member variable of a class declared in the namespace .

+4
source

Source: https://habr.com/ru/post/978512/


All Articles