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

Use of bitand on boolean operands #77601

Closed
peter-harmann-tfs opened this issue Jan 10, 2024 · 0 comments · Fixed by #81976
Closed

Use of bitand on boolean operands #77601

peter-harmann-tfs opened this issue Jan 10, 2024 · 0 comments · Fixed by #81976
Labels
clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer enhancement Improving things as opposed to bug fixing, e.g. new or missing feature

Comments

@peter-harmann-tfs
Copy link

peter-harmann-tfs commented Jan 10, 2024

The following code gives a warning as expected:

bool test();
int main() {
    return test() & test();
}

warning: use of bitwise '&' with boolean operands [-Wbitwise-instead-of-logical])

However, this code also gives the same warning:

bool test();
int main() {
    return test() bitand test();
}

I believe it would be best not to give the warning in the second case. There is no risk of the second case being accidental typo. It would be a nice way of signaling the bitwise AND is intentional to the compiler, rather than casting one of the bools to an int.

@dtcxzyw dtcxzyw added enhancement Improving things as opposed to bug fixing, e.g. new or missing feature clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer and removed new issue labels Jan 10, 2024
AaronBallman pushed a commit that referenced this issue Mar 18, 2024
)

This pull request fixes #77601 where using the `bitand` operator with
boolean operands should not trigger the warning, as it would indicate an
intentional use of bitwise AND rather than a typo or error.

Fixes #77601
chencha3 pushed a commit to chencha3/llvm-project that referenced this issue Mar 23, 2024
…m#81976)

This pull request fixes llvm#77601 where using the `bitand` operator with
boolean operands should not trigger the warning, as it would indicate an
intentional use of bitwise AND rather than a typo or error.

Fixes llvm#77601
devnexen pushed a commit to devnexen/llvm-project that referenced this issue Mar 23, 2024
…m#81976)

This pull request fixes llvm#77601 where using the `bitand` operator with
boolean operands should not trigger the warning, as it would indicate an
intentional use of bitwise AND rather than a typo or error.

Fixes llvm#77601
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer enhancement Improving things as opposed to bug fixing, e.g. new or missing feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants