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

-Wconstant-logical-operand should not fire for expressions involving macros #63963

Open
AaronBallman opened this issue Jul 19, 2023 · 0 comments
Labels
clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer quality-of-implementation

Comments

@AaronBallman
Copy link
Collaborator

Clang currently issues this diagnostic when the constant in question is a macro, as in (live example):

#ifndef X
#define X 0
#endif

#ifndef Y
#define Y 2
#endif

bool foo() {
  return X || Y;
}

I think any use of a macro should suppress the diagnostic on the assumption that the macro value is constant for one configuration but may not be constant in all configurations. However, I can also see why we might want to still diagnose macro uses, such as cases like:

void func(int error) {
  if (ENOMEM || error == 12)
    ...
}

where the user could have forgotten to add error == to the expression. So it might be that we want to split this off into separate diagnostic groups.

Relates to discussion in https://reviews.llvm.org/D142609

@AaronBallman AaronBallman added quality-of-implementation clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer labels Jul 19, 2023
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 quality-of-implementation
Projects
None yet
Development

No branches or pull requests

1 participant