<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/107562>107562</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang] an issue with compound literals ?
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
swordkill
</td>
</tr>
</table>
<pre>
**Hi Humans,**
> Last year I shared an issue related to VLA and Blocks (extension) :
https://github.com/llvm/llvm-project/issues/63412
I come back for one more embarrassing, related either to C99 compound literals, or C11 _Generics or _Static_assert.
Here is a reproduction :
https://godbolt.org/z/9dTa4YP4n
### The purpose is to be able to use static assertion within an expression.
```c
/*
** Using -std=c23.
**
** The trick is that static_assert is garanteed by the standard
** to not produce anything :
**
** - https://en.cppreference.com/w/c/language/_Static_assert
**
** """Otherwise,
** if expression does not equal zero, nothing happens;
** no code is emitted.
** """
**/
#define static_expr(e) \
( !! sizeof (struct {static_assert (e); char c;}) )
#define is_same(e1, e2) \
_Generic (&(typeof_unqual (e1)) {} \
, typeof_unqual (e2) * : true \
, default : false \
)
```
### The issue
```c
/*
** It's OK.
**/
typeof ((size_t) {i}) witness_one;
typeof_unqual ((size_t) {i}) witness_two;
/*
** It's OK.
**/
is_same (witness_one, (size_t) {i});
is_same (witness_two, (size_t) {i});
/*
** It's OK.
**/
static_assert (is_same (witness_one, (size_t) {i}));
/*
** It's KO.
** [clang] error: initializer element is not a compile-time constant
** [gcc ] everything is good buddy
**/
static_expr (is_same (witness_one, (size_t) {i}));
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJykVl-P4jYQ_zTmZbQocYDAAw8LNL3TnbSVeq3UJ-TYA3HX2KntLMd--mqSLEtYru1uIwuI8cz85jd_PCIEvbeISzZdselmJJpYOb8MR-fVozZmVDp1WjJ-z_j9Jw2fmoOwgfF1t8OSDUtePrOf4KsIEU4oPHyGUAmPCoQFHUKD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