<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/57726>57726</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [clang-tidy] False positive from misc-redundant-expression with dependent conditionals
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          al42and
      </td>
    </tr>
</table>

<pre>
    In the following code, `ALLOW_ARGS` is a PP macro. When it is set to 0, clang-tidy complains about the redundant expression (annotated).

Technically, the expression is indeed redundant in this case, but the parent condition makes it clear that we are not interested in this comparison when `sc_allowArgs` is false.

```cpp
static constexpr bool sc_allowArgs = (ALLOW_ARGS != 0);
static constexpr int sc_maxArgs = sc_allowArgs ? 10 : 0;

int main(int argc, char **argv) {
  if constexpr (sc_allowArgs) {
    if (argc < 0 || argc >= sc_maxArgs) { // <<
      return -1;
    }
  }
  return 0;
}
```

```
$ clang-tidy-15 -checks=misc-redundant-expression test.cpp -- -DALLOW_ARGS=0 -std=c++17
1 warning generated.
/tmp/test.cpp:6:18: warning: logical expression is always true [misc-redundant-expression]
    if (argc < 0 || argc >= sc_maxArgs) {
```

Godbolt: https://godbolt.org/z/3P9914MWb
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJylVE1v2zgQ_TXSZSBDpCzJOujgxOtigS4a7C6QY0GRjMQtTQokFTf99TuUZUcJml4KUBS_5s2beRx2Vry0fxoIg4Qnq7U9K9MDt0Im9B6SKt9__vzl8ev-70__4ASUBwYPD3Bi3NkNPA7SgApx2csAwUIezbhmps-CEi-IdBo1UwbtOjuF2Y-TYjKCmQDy--ik98oaSOiOGWMDC1IktNkk-SHJ95f-X8kHozjT-iXCR4yVJTpXRkgpVsAqRoQbnPk5kG5xPTIncZtbI1SIxif2TfoYAteSOTzDApwl4DFAMogTJPpBTq-QGBFzyqPxOYaPafH8K4up27veL1l6YtrLN0HgxqXxcbyseAxW8UgGHWA80FmrYQ0GSXGImXkVAWckLmKem6S4-wAIaUecE_t-Q3kHewSS42-PQFeUSx9NTygYeo1D5no-SzpgdhK6x4ZLz-gdknoxBFBPK-do-SYhb4_Oh6PYCIwE7gFp1PfYYFn5Y2G7kF_M0eSILVrEdgMDFD1MzkBGboHE1aQ-XCer4XJ2FfN176bOTyVbpnS7utoZKSHjg-TfPDI-Kc-z2_3LVtcz4PXZoOaQZZAdVuVUHHLIfBA4wBTfYSP1xRGBM3MmFmIvjXSxJK5XiR7DaYz9gooSVviRXdRysYpDbftYMO_qhOkze_EQ3CQhKe8-JJ2Uh9_U6xdZ_WRFZ3WILIcQRsze_iJuf9nYWNfj7Ad-xUPTkO1fj10qW1JVBckLUu9S0RaiKRqWBhW0bDGSV1mQOhxj8cFoPdb4M75rzp7gY4HOKgwg5CjxEVm_DQiSTk6370ji6anb4CuAE62fr79sdPY_yQNOlfeTxEQcy7qmVTq0VGx5JQhhjDeEVEVdVrhRl2xX0obUNNWsk9rHQBJKjTzDDIFjjCZVLc0pzRtSUJJXZLdhHSsI54wWFX0qS5Zsc4klqzeRR8xe6tqZUjehHttcKx_86ybDsHsj57xFfDaFwbqW6S1lRqSz63am_j8GXuC6">