itiviti-cpp-analyzer
itiviti-cpp-analyzer copied to clipboard
'const-param' warning for mutable std::bitset instance
Description
Analyzer suggest adding 'const' qualifier for mutable std::bitset instance that changes in the for-loop.
Example
foo.h
#include <bitset>
struct A {
static const int length = 128;
static void bar(std::bitset<length> & a, const std::bitset<length> & b, int a_start = 0, int b_start = 0);
}
foo.cpp
void A::bar(std::bitset<length> & a, const std::bitset<length> & b, int a_start, int b_start)
{
for (int i = a_start, j = b_start; i < A::length && j < A::length; ++i, ++j) {
int sum = static_cast<int>(a[i]) + static_cast<int>(b[j]);
a[i] = static_cast<bool>(sum % 2);
}
}
Compiler message
[ 5%] Building CXX object CMakeFiles/expressions_lib.dir/src/foo.cpp.o
error: 'a' can have 'const' qualifier [const-param]
void A::bar(std::bitset<length> & a, const std::bitset<length> & b, int a_start, int b_start)
^
1 error generated.
Build info
Clang 11.0.0
@EgorkaZ could you please take a look?