Skip to content

[clang-tidy] Incorrect suggestion for readability-simplify-boolean-expr #163128

@ChuanqiXu9

Description

@ChuanqiXu9

Reproducer: https://godbolt.org/z/cKfnavMvb

#include <string>
#include <iostream>
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:

<source>: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);
      |          ^   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:13:10: note: Value stored to 'x' during its initialization is never read
   13 |     bool x = !(app == fileMeta.appName && maxCopy == fileMeta.maxCopy);
      |          ^   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>: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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang-tidyinvalid-code-generationTool (e.g. clang-format) produced invalid code that no longer compiles

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions