Reputation: 306
When setting the size of a std::array in a class definition using a static const as the size, cppcheck doesn't know how large the array is. So it thinks I'm out of bounds when I'm not
Doing a #define seems to solve the problem so this is an academic question.
class A
{
A() : myArr()
{
myArr[0]=100;
}
static const int SOMEVAL = 4;
std::array<double, SOMEVAL+1> myArr;
int getVal() { return myArr[1]; };
}
int main(void)
{
A myA;
myA.getVal();
}
Any thoughts?
Upvotes: 3
Views: 201
Reputation: 18210
This was a defect in cppcheck:
https://trac.cppcheck.net/ticket/9202
Which has been fixed in the 1.89 release:
https://trac.cppcheck.net/changeset/121093658d788126d5f94792c4ea00447fdbb979/
Upvotes: 1