Debian Codegraph @

clang/test/Sema/gh87867.c

raw
1 // RUN: %clang_cc1 -fsyntax-only -verify -std=c23 %s
2
3 // Compound literal doesn't need a constant expression inside a initializer-list if it is already inside a function
4 // see: https://github.com/llvm/llvm-project/issues/87867
5 int foo(int *a, int b) {
6 return 0;
7 }
8
9 int x;
10 struct{int t;} a = (struct {
11 typeof(foo(&(struct { int t; }){.t = x}.t, 0)) t; // expected-error {{initializer element is not a compile-time constant}}
12 }){0};
13
14 void inside_a_func(){
15 int x;
16 (void)(struct {
17 typeof(foo(&(struct { int t; }){.t = x}.t, 0)) t;
18 }){0};
19 }
20
21 // see: https://github.com/llvm/llvm-project/issues/143613
22 #define bitcast(type, value) \
23 (((union{ typeof(value) src; type dst; }){ (value) }).dst)
24
25 double placeholder = 10.0;
26 double bar = bitcast(double, placeholder); // expected-error {{initializer element is not a compile-time constant}}
27
28 int main(void)
29 {
30 int foo = 4;
31 foo = bitcast(int, bitcast(double, foo));
32 return 0;
33 }