Skip to content

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

@sn1tr0n

Description

@sn1tr0n

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions