Skip to content

[clang-tidy] inconsistent handling of comparisons in readability-redundant-parentheses #192463

@firewave

Description

@firewave
#include <map>
#include <string>

bool f1()
{
    std::map<int, int> m;
    auto it = m.find(0);
    return (it != m.cend());
}

bool f2(int i)
{
    return (i == 0); // no warning
}

int f3(const std::string& s)
{
    return (s >= "0");
}
<source>:8:12: warning: redundant parentheses around expression [readability-redundant-parentheses]
    8 |     return (it != m.cend());
      |            ^              ~
<source>:18:12: warning: redundant parentheses around expression [readability-redundant-parentheses]
   18 |     return (s >= "0");
      |            ^        ~

https://godbolt.org/z/EvPde1hbq

I would have expected the warning in all three cases.

But I think having the parentheses around a comparison might actually have better readability (especially if there is multiple conditions) so I would like to have an option to control that.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang-tidyenhancementImproving things as opposed to bug fixing, e.g. new or missing feature
    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions