blob: 08daa5f8d6ee0f3cbfa915c6d4615b32532555ec [file] [log] [blame]
Daniel Dunbard7d5f022009-03-24 02:24:46 +00001// RUN: clang-cc -fsyntax-only -verify %s
Eli Friedman4efaa272008-11-12 09:44:48 +00002
3#define EVAL_EXPR(testno, expr) int test##testno = sizeof(struct{char qq[expr];});
4int x;
5EVAL_EXPR(1, (_Bool)&x)
6EVAL_EXPR(2, (int)(1.0+(double)4))
7EVAL_EXPR(3, (int)(1.0+(float)4.0))
8EVAL_EXPR(4, (_Bool)(1 ? (void*)&x : 0))
9EVAL_EXPR(5, (_Bool)(int[]){0})
10struct y {int x,y;};
11EVAL_EXPR(6, (int)(1+(struct y*)0))
12EVAL_EXPR(7, (int)&((struct y*)0)->y)
13EVAL_EXPR(8, (_Bool)"asdf")
Eli Friedmana6afa762008-11-13 06:09:17 +000014EVAL_EXPR(9, !!&x)
15EVAL_EXPR(10, ((void)1, 12))
16void g0(void);
17EVAL_EXPR(11, (g0(), 12)) // FIXME: This should give an error
18EVAL_EXPR(12, 1.0&&2.0)
19EVAL_EXPR(13, x || 3.0)
Anders Carlsson4bbc0e02008-11-24 04:21:33 +000020
21unsigned int l_19 = 1;
22EVAL_EXPR(14, (1 ^ l_19) && 1); // expected-error {{fields must have a constant size}}
Anders Carlsson35873c42008-11-24 04:41:22 +000023
24void f()
25{
26 int a;
27 EVAL_EXPR(15, (_Bool)&a); // expected-error {{fields must have a constant size}}
28}
Daniel Dunbar8f826f02009-01-24 19:08:01 +000029
30// FIXME: Turn into EVAL_EXPR test once we have more folding.
31_Complex float g16 = (1.0f + 1.0fi);
Daniel Dunbar2d6744f2009-02-18 00:47:45 +000032
33// ?: in constant expressions.
34int g17[(3?:1) - 2];
Anders Carlsson4d4c50d2009-02-19 04:55:58 +000035
Anders Carlssone2f0e962009-02-19 06:19:15 +000036EVAL_EXPR(18, ((int)((void*)10 + 10)) == 20 ? 1 : -1);
Anders Carlsson1c176892009-02-19 06:30:50 +000037
38struct s {
39 int a[(int)-1.0f]; // expected-error {{array size is negative}}
40};
Eli Friedmane8761c82009-02-20 01:57:15 +000041
42EVAL_EXPR(19, ((int)&*(char*)10 == 10 ? 1 : -1));
Daniel Dunbar4fff4812009-02-21 18:14:20 +000043
44EVAL_EXPR(20, __builtin_constant_p(*((int*) 10), -1, 1));
Eli Friedman722c7172009-02-28 03:59:05 +000045
46EVAL_EXPR(21, (__imag__ 2i) == 2 ? 1 : -1);
47
48EVAL_EXPR(22, (__real__ (2i+3)) == 3 ? 1 : -1);
49
Anders Carlsson1a7acfa2009-02-28 21:56:50 +000050int g23[(int)(1.0 / 1.0)] = { 1 };
51int g24[(int)(1.0 / 1.0)] = { 1 , 2 }; // expected-warning {{excess elements in array initializer}}
52int g25[(int)(1.0 + 1.0)], g26 = sizeof(g25);
Eli Friedmana1f47c42009-03-23 04:38:34 +000053
54EVAL_EXPR(26, (_Complex double)0 ? -1 : 1)
55EVAL_EXPR(27, (_Complex int)0 ? -1 : 1)
56EVAL_EXPR(28, (_Complex double)1 ? 1 : -1)
57EVAL_EXPR(29, (_Complex int)1 ? 1 : -1)
Chris Lattner81045d82009-04-21 05:19:11 +000058
59
60// PR4027 + rdar://6808859
61struct a { int x, y };
62static struct a V2 = (struct a)(struct a){ 1, 2};
63static const struct a V1 = (struct a){ 1, 2};