Skip to content

[clang-tidy] Incorrect autofix ignoring the correct precedence #161318

@ChuanqiXu9

Description

@ChuanqiXu9

Reproducer:

#include <stdint.h>
#include <iostream>
int main()
{
    uint32_t val = -1;

    size_t bytesOut = 1;
    std::cout << std::hex << val << std::endl;
    while(val >>=7) {
        std::cout << std::hex << val << std::endl;
        bytesOut++;
    }

    std::cout << bytesOut << std::endl;
}

with readability-implicit-bool-conversion check, it will be rewritten to:

while(val >>=7 != 0) 

but != has higher precedence, so it is actually:

while(val >>= (7!=))

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions