itiviti-cpp-analyzer icon indicating copy to clipboard operation
itiviti-cpp-analyzer copied to clipboard

'const-param' warning for mutable std::bitset instance

Open sn1tr0n opened this issue 3 years ago • 1 comments

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

sn1tr0n avatar May 21 '22 11:05 sn1tr0n

@EgorkaZ could you please take a look?

sovulken avatar Jun 02 '22 14:06 sovulken