34 lines · c
1// RUN: %clang_cc1 -fsyntax-only -verify -std=c23 %s2 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/878675int foo(int *a, int b) {6 return 0;7}8 9int x;10struct{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 14void 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/14361322#define bitcast(type, value) \23 (((union{ typeof(value) src; type dst; }){ (value) }).dst)24 25double placeholder = 10.0;26double bar = bitcast(double, placeholder); // expected-error {{initializer element is not a compile-time constant}}27 28int main(void)29{30 int foo = 4;31 foo = bitcast(int, bitcast(double, foo));32 return 0;33}34