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

    <tr>
        <th>Summary</th>
        <td>
            wrong fix of clang-tidy bugprone-macro-parentheses
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang-tidy
      </td>
    </tr>

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

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

<pre>
    In this program

```
#define my_cast(type, p) reinterpret_cast<type*>(p)

void foo(void *p)
{
 (void)my_cast(int, p);
}
```

This command
` % /grid/common/test/llvm-v17.0.6d1rh74_lnx86/bin/clang-tidy --fix --checks=bugprone-macro-parentheses bugprone-macro-parentheses.cpp -- -std=c++17 -stdlib=libc++`
converts the macro to
`#define my_cast(type, p) (reinterpret_cast<(type)*>(p))
`
And then the compilation fails
```
% /grid/common/test/llvm-v17.0.6d1rh74_lnx86/bin/clang++ -c -std=c++17 -stdlib=libc++ bugprone-macro-parentheses.cpp
bugprone-macro-parentheses.cpp:10:11: error: expected a type
    5 |     (void)my_cast(int, p);
      | ^
bugprone-macro-parentheses.cpp:6:44: note: expanded from macro 'my_cast'
    1 | #define my_cast(type, p) (reinterpret_cast<(type)*>(p))
      | ^
bugprone-macro-parentheses.cpp:10:11: error: expected '>'
bugprone-macro-parentheses.cpp:6:50: note: expanded from macro 'my_cast'
    1 | #define my_cast(type, p) (reinterpret_cast<(type)*>(p))
      | ^
bugprone-macro-parentheses.cpp:10:11: note: to match this '<'
bugprone-macro-parentheses.cpp:6:43: note: expanded from macro 'my_cast'
    1 | #define my_cast(type, p) (reinterpret_cast<(type)*>(p))
      | ^
bugprone-macro-parentheses.cpp:10:11: error: expected expression
    5 |     (void)my_cast(int, p);
      | ^
bugprone-macro-parentheses.cpp:6:51: note: expanded from macro 'my_cast'
    1 | #define my_cast(type, p) (reinterpret_cast<(type)*>(p))
      | ^
3 errors generated.
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzcVk2PpDYQ_TXFpUQLbNzAgUN_bEu5574ydjV4F2xkuycz_z4C-mOS7GRmE0XRrtSy3FS136tX1X7IEExniRoQexDHRF5i73zzRaqvF8lY0jr90vxiMfYm4ORd5-UI2RGy3XXdZtfP-pVxTWdjCceXz0qGCKyKLxMBO-AErEZPxkbyk6e4xvlhje-AfwJWzUmvz39yRuPZOWDVsgW2e5VS7tcNXsPA6geusfEGC3x_-8Xx27yX9de5SOXGUVp9T0NgAoGdOj-ff5rDzgI7RZpRTsPwNKZPebnJNlud-74sPg_2udoCO7VmzlODtF0ajX7BND2bZ0xT1ZP6GoAf20s3eWcpHaXyLp2kJxt7ChTw7dBGTROmKaYhauBHBWwPbJ-Xy4PBtMCPg2mvj-8VKmefyMeAsSdczsToHlq81zdg1Tdad8-q_9jAe4Nu6DurZ2C7oCs3TmaQ0TiLZ2mG8MYo_XvZVw0wVR8T6x3RV17v5PBdns1LDnyH5L3zy-Z5IhVJo8RFsHVqEVEglId58-ERxjW7PCCITx-ktAW-K4qZiHWRroSk1aTx7N14nQdg5R26fIDlK9h_MyH_pJq_FXimPsOU3yGNyH5CaW7lRIejjKpfr_BFnsP3yVPwn1Cev04OPU-eQjDO_h9_T5H_ICLzVbqAHVnyMpLe_On-TnTDdc1rmVCTl3lRC17UIukbWW1zrknnIqtzJvO6yLYVP-tMlkLXrEhMwzJWZCITjIsqF5utFowkq5Qqa1m1FRQZjdIMm_n-3zjfJSaECzV1nguRDLKlISyvMow9fBcYm19tfLOYRnvpAhTZYEIMj2OiiQM1v3lnO5xN2p3xlXG_3cHk4oemj3EKwHfATrNjmdhf2o1y49WnbnY1efeF1OxeC-kA7LTw_j0AAP__MAfYMw">