[clang-tidy] Incorrect suggestion for readability-simplify-boolean-expr
Nobody has claimed this yet.
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Reproducer: https://godbolt.org/z/cKfnavMvb
```
#include
#include
struct Foo {
std::string appName;
int maxCopy;
};
int main()
{
std::string app;
Foo fileMeta;
int maxCopy;
bool x = !(app == fileMeta.appName && maxCopy == fileMeta.maxCopy);
}
```
clang-tidy shows:
```
:13:10: warning: Value stored to 'x' during its initialization is never read [clang-analyzer-deadcode.DeadStores]
13 | bool x = !(app == fileMeta.appName && maxCopy == fileMeta.maxCopy);
| ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:13:10: note: Value stored to 'x' during its initialization is never read
13 | bool x = !(app == fileMeta.appName && maxCopy == fileMeta.maxCopy);
| ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:13:14: warning: boolean expression can be simplified by DeMorgan's theorem [readability-simplify-boolean-expr]
13 | bool x = !(app == fileMeta.appName && maxCopy == fileMeta.maxCopy);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| ! || !=
2 warnings generated.
```
But it should be `app != fileMeta.appName || maxCopy != fileMeta.maxCopy)`
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the clang-tidy readability-simplify-boolean-expr check and reproduce the warning using the linked Compiler Explorer example. Compare the suggested DeMorgan transformation with the expected app != fileMeta.appName || maxCopy != fileMeta.maxCopy result, then add or update coverage for this expression so the diagnostic and replacement are correct.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100