Issue 152274
Summary Compilation error when trying to cast to pointer-to-array with typeof() in C++
Labels clang
Assignees
Reporter Michael137
    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?
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to