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

    <tr>
        <th>Summary</th>
        <td>
            Inconsitency between clang-cl and clang-tidy preprocessor and cl.exe
        </td>
    </tr>

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

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

    <tr>
      <th>Reporter</th>
      <td>
          sandy-carter-unity
      </td>
    </tr>
</table>

<pre>
    There is a way to get a `invalid preprocessing token` in clang-cl which does not occur on MSVC and this running clang-tidy with compilation database made from MSVC difficult.

This seems to happen in a macro when concatenating/pasting inside of a parens with this pattern `(##name##)` , `(##name##*)` or `(something##name##)`. It does not happen with this pattern `(##name)` , `(##name*)` or `(something##name)`.

This is potentially related to #27754

### Example 1
```c
#define ReproCase1(bits) static (__int##bits##) foo = 0;
ReproCase1(8)
```
#### MSVC
```
cl.exe /nologo /c /E test.c
test.c
#line 1 "test.c"

static (__int8) foo = 0;
```

#### Clang
```
clang-cl.exe /c /E .\test.c                                                                                                                                             ❮   1  
# 1 ".\\test.c"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 368 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 ".\\test.c" 2

static (.\test.c(2,1): error: pasting formed '__int8)', an invalid preprocessing token [-Winvalid-token-paste]
    2 | ReproCase1(8)
      | ^
.\test.c(1,45): note: expanded from macro 'ReproCase1'
    1 | #define ReproCase1(bits) static (__int##bits##) foo = 0;
      |                                             ^
__int8) foo = 0;
1 error generated.
```

### Example 2
```c
#define ReproCase2(bits)           \
static void set_zero(void* result) \
{                                  \
    *(__int##bits##*)result = 0;   \
}
ReproCase2(8)[-Winvalid-token-paste]
```
#### MSVC
```
cl.exe /nologo /c /E test.c
test.c
#line 1 "test.c"





static void set_zero(void* result) { *(__int8*)result = 0; }
```

#### Clang
```
clang-cl.exe /c /E .\test.c                                                                                                                                             ❮   1  
# 1 ".\\test.c"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 368 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 ".\\test.c" 2





static void set_zero(void* result) { *(.\test.c(6,1): error: pasting formed '__int8*', an invalid preprocessing token [-Winvalid-token-paste]
    6 | ReproCase2(8)
      | ^
.\test.c(4,18): note: expanded from macro 'ReproCase2'
    4 |     *(__int##bits##*)result = 0;   \
      |                  ^
__int8*)result = 0; }
1 error generated.
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsV19v6rgT_TTDywiUOH954IEGkO7D7-W3V7uPV44zEO8mdmSb27KffmUSINDSUu1d6Uq7VUVdPB6fczw-I3Nr5U4RLSB5gmQ14XtXa7OwXFWHqeDGkZnulXSHSamrw-JrTYZQWuT4zA_oNO7IIUdIA6m-80ZW2BnqjBZkrVQ7dPoPUpAGKBWKhqvdVDT4XEtRY6XJotIOtRB7g1rh_375tUCuKnS1tGj2SvkU_TInqwM-S1ej0G0nG-6kVlhxx0tuCVteEW6Nbvskldxupdg3bgbBCoJl__nVp7VErfXIa951pDwwji0XRuNzTQqFVoI7UtxJtQO26bj1I5TKyopQb5Fjxw0p28M5Yu24c2SU1wFYDiwCFineUj8CNvcSACvuBiyHGG2GEKtbcvURwlvJZvjFXRQcqDyC5x0kj2E47v5KVb-ndqSc5E1zQEMNd1R5mYFFLMuSeLzkxCTC9Qtvu4YwHCbSoP8V58CKtlIR_t9XVcEthcDyUjoLbI7WcScFAsu_fZPK9Tn7yUEq3GqNEK0wgOipz3mVKfeErre-gehR-pp6M0o0M3ohBLZRutE7z3bj8WzW6Mi62UBjPAYWNZ5QiMDYMMHYWJ0bVvnbNG7xvkZd-ItzB3Z_E0_gB8gzSIoeEf5MP7BmMF_Bcu2HG5gXkCcYIp4p91p69GcCF0lP0xAV5V42bioVRGtg7Fxz9yOiS0SU5h_GnLII3bbexvw5P7zXLd5bOninRmajoJ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