<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/152274>152274</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Compilation error when trying to cast to pointer-to-array with typeof() in C++
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Michael137
</td>
</tr>
</table>
<pre>
Came up in https://github.com/llvm/llvm-project/issues/152113
When trying to perform following cast:
```
int main() {
char *s = "abc";
(typeof(*s)(*)[3])s;
}
```
Clang (and GCC FWIW), produce following error ([godbolt](https://godbolt.org/z/M7Ye8o3G4)):
```
main.cpp:6:18: error: expected expression
6 | (typeof(*s)(*)[3])s;
```
But this works fine in C ([godbolt](https://godbolt.org/z/j33qrGv1r)).
However, wrapping the `typeof` in another `typeof` works fine in both C ([godbolt](https://godbolt.org/z/fr1WP7eGo)) and C++ ([godbolt](https://godbolt.org/z/4z7xhPfGn)):
```
int main() {
char *s = "abc";
*(typeof(typeof(*s))(*)[3])s;
}
```
What's the correct behaviour here?
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJykVE-PuzYQ_TTDxdrI2Pw9cCBEpD38pL1FPRozCd4STG2TbPbTVzapmt1VD5tKSIyMmXnz5s0T1qrThFhBuoV0F4nFDdpUv5QcBI4xz6NO97eqEWcky0zURAbnZgu8BtYCa0_KDUu3kfoMrB3Hyz-vl9noN5QOWKusXdACa-OUxTEHWgOtDwNOxJmbmk7EaTKjOWpzJkc9jvrqD6WwzlehNWT0_tBaTY6chZqAFcBKAvkWaE0IIXIQhgCrLQG-I8CY6CQwBjxcAFa424z6GP6rLbByjXyQbjmkO2ClXW9DvvtStRnFdPJJxNSTfdOQ9vD7IeRoyGx0v0h8QI7GaI-lgHR70n2nRxfyF1-YWz9ttDkBaz-Atb_yP7DQfJ-E1OX37n3nGznPwOsMeB0XwOu1XAjeZ5QOex8YtFbp6U5ORiBvfPBDIh5KbxdH3KAsuWrzpyVHNaEXQ_NMn2-c_2X2l9isfW5WRfymr3hB4zm9GjHPQRkDEsjoHXJGfUkxaTeg-Xz-GVWn3fActKOJD6857vUKjfiBN8C2wLbPpEs-8vfh9bif_muiT-o5TLJ-HOb3qf5I4WEjhQOW20C61MagdKTDQVyUXgwZ0CDwNuor3pe8FBFWcZ4mSU6LrIyGKk9kXHIuOi5ikR0pLwqWJUVGZSdzWXaRqhhlKS1oRksa03IjaJHGvCx42Re84xQSimehxo33D09iFJyjilPG8iQaRYejDT7FmPQb6flId5GpguF0y8lCQkdlnf03hVNuxKrR51mNwik93dfz-tl_vNsEH9JqcmhenH4RxogbuSo3kAdyy6D6VRHRYsbqf9mh7-tSsb8DAAD__yarnBg">