<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/143613>143613</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
C23 Clang rejects valid code involving compound literal and typeof
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
dcawley15
</td>
</tr>
</table>
<pre>
I was attempting to create a generic bit cast macro using the new C23 typeof feature. Clang appears to reject the following code with "_error: initializer element is not a compile-time constant_" even though I believe this code is valid in C23. Both GCC and MSVC (with /std:clatest) accept this code.
``` c
#include <stdint.h>
#define bitcast(type, value) \
(((union{ typeof(value) src; type dst; }){ (value) }).dst)
int main(void)
{
int64_t foo = 4;
double bar = bitcast(double, foo); // ok
foo = bitcast(int64_t, bar); // ok
foo = bitcast(int64_t, bitcast(double, foo)); // error
return 0;
}
```
Compiler Flags: -std=c23 -pedantic
https://godbolt.org/z/zsfErTo1e
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJycVMGO4zYM_Rr5QsSwJScZH3zIeDbFHnpq0etAlmhbrSwZEp1g9usLRZ5mWqCXBRQkMR8fH2k-yRjN5BA7dnxlx7dCbjT70Gkl7xY_6mMxeP3RfYe7jCCJcFnJuAnIgwooCUHChA6DUTAYAiUjwSJV8LDFB3BGcHiHngugjxX9CCNK2gKW0FvpJpDrijLERBnwT1T0yBm9tf6eGJTXCHdDMzDO3zEEH5i4gHGGjLTmBwZAiws6AhPBeQIJyi-rsXggsyAo7yJJR--Mc8AbOqDZb9MM32FAa_CGQLOJuZCJcJPWaDAuaS7h1dMMv_Q9SKfh19_-6IHxl13ONZJm4qKsJIzEeAtSKVzpyVey6pLOqcoHVPrHhXHKbhqBiT6SNo7KmYlvO5gLjaNxmCaaBsr4Sxod433StmEqxI49qy5JSz6bM96x8-s-ZMZf_oHGoJjIAdCR0m92fmO8TfCvwPy01I9Wshbj0us0LsG80fvz82uqDQDG0al5Jxi9BybeoGHiM6T9NliEQYZH5NlKDqRmRu8TYdLDr4xfwf-1J3_yPbP2SiltkOGn0v5fwb_Y8oZlwoC0BQdVbivN58u7zBPq86oFuFo5xbSZh8dWvCku4LCilo6MytiZaE2QXGnyevCWSh8mxq8_0ieO38LvvsZ9EapLoTuhW9HKArv63LTHVjRNW8ydGLQ-n098eKlOZ17pqj3WbdM0shG1GNu2MB2v-LE61RXnddW05dCeuK6PSlWnqhrPDWsqXKSxpbW3JYkoTIwbdnUjTrUorBzQxse1wLlKTmWcpxsidCnhMGxTZE1lTaT4pCBDFrtk9mzu7OhPT2WHuZu3t-zsZfWb02ANYZD2YbG8v8UWbPefcRmat6FUfmH8mgruX4c1-FSE8eujgcj4de_h1vG_AwAA___4eoFi">