xref: /aosp_15_r20/external/clang/test/Sema/static-init.c (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // RUN: %clang_cc1 -fsyntax-only -verify -Wno-bool-conversion %s
2*67e74705SXin Li 
3*67e74705SXin Li typedef __typeof((int*) 0 - (int*) 0) intptr_t;
4*67e74705SXin Li 
5*67e74705SXin Li static int f = 10;
6*67e74705SXin Li static int b = f; // expected-error {{initializer element is not a compile-time constant}}
7*67e74705SXin Li 
8*67e74705SXin Li float r  = (float) (intptr_t) &r; // expected-error {{initializer element is not a compile-time constant}}
9*67e74705SXin Li intptr_t s = (intptr_t) &s;
10*67e74705SXin Li _Bool t = &t;
11*67e74705SXin Li 
12*67e74705SXin Li 
13*67e74705SXin Li union bar {
14*67e74705SXin Li   int i;
15*67e74705SXin Li };
16*67e74705SXin Li 
17*67e74705SXin Li struct foo {
18*67e74705SXin Li   short ptr;
19*67e74705SXin Li };
20*67e74705SXin Li 
21*67e74705SXin Li union bar u[1];
22*67e74705SXin Li struct foo x = {(intptr_t) u}; // expected-error {{initializer element is not a compile-time constant}}
23*67e74705SXin Li struct foo y = {(char) u}; // expected-error {{initializer element is not a compile-time constant}}
24*67e74705SXin Li intptr_t z = (intptr_t) u; // no-error
25