Issue 107562
Summary [clang] an issue with compound literals ?
Labels clang
Assignees
Reporter swordkill
    **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}));
```


_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to