Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
snitron opened this issue May 21, 2022 · 1 comment
Open

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

snitron opened this issue May 21, 2022 · 1 comment

Comments

@snitron
Copy link

snitron commented May 21, 2022

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

@sovulken
Copy link
Collaborator

sovulken commented Jun 2, 2022

@EgorkaZ could you please take a look?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants