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