2009-03-24 10:24:46 +08:00
|
|
|
// RUN: clang-cc -fsyntax-only -verify %s
|
2008-11-12 17:44:48 +08:00
|
|
|
|
|
|
|
#define EVAL_EXPR(testno, expr) int test##testno = sizeof(struct{char qq[expr];});
|
|
|
|
int x;
|
|
|
|
EVAL_EXPR(1, (_Bool)&x)
|
|
|
|
EVAL_EXPR(2, (int)(1.0+(double)4))
|
|
|
|
EVAL_EXPR(3, (int)(1.0+(float)4.0))
|
|
|
|
EVAL_EXPR(4, (_Bool)(1 ? (void*)&x : 0))
|
|
|
|
EVAL_EXPR(5, (_Bool)(int[]){0})
|
|
|
|
struct y {int x,y;};
|
|
|
|
EVAL_EXPR(6, (int)(1+(struct y*)0))
|
|
|
|
EVAL_EXPR(7, (int)&((struct y*)0)->y)
|
|
|
|
EVAL_EXPR(8, (_Bool)"asdf")
|
2008-11-13 14:09:17 +08:00
|
|
|
EVAL_EXPR(9, !!&x)
|
|
|
|
EVAL_EXPR(10, ((void)1, 12))
|
|
|
|
void g0(void);
|
|
|
|
EVAL_EXPR(11, (g0(), 12)) // FIXME: This should give an error
|
|
|
|
EVAL_EXPR(12, 1.0&&2.0)
|
|
|
|
EVAL_EXPR(13, x || 3.0)
|
2008-11-24 12:21:33 +08:00
|
|
|
|
|
|
|
unsigned int l_19 = 1;
|
|
|
|
EVAL_EXPR(14, (1 ^ l_19) && 1); // expected-error {{fields must have a constant size}}
|
2008-11-24 12:41:22 +08:00
|
|
|
|
|
|
|
void f()
|
|
|
|
{
|
|
|
|
int a;
|
|
|
|
EVAL_EXPR(15, (_Bool)&a); // expected-error {{fields must have a constant size}}
|
|
|
|
}
|
2009-01-25 03:08:01 +08:00
|
|
|
|
|
|
|
// FIXME: Turn into EVAL_EXPR test once we have more folding.
|
|
|
|
_Complex float g16 = (1.0f + 1.0fi);
|
2009-02-18 08:47:45 +08:00
|
|
|
|
|
|
|
// ?: in constant expressions.
|
|
|
|
int g17[(3?:1) - 2];
|
2009-02-19 12:55:58 +08:00
|
|
|
|
2009-02-19 14:19:15 +08:00
|
|
|
EVAL_EXPR(18, ((int)((void*)10 + 10)) == 20 ? 1 : -1);
|
2009-02-19 14:30:50 +08:00
|
|
|
|
|
|
|
struct s {
|
|
|
|
int a[(int)-1.0f]; // expected-error {{array size is negative}}
|
|
|
|
};
|
2009-02-20 09:57:15 +08:00
|
|
|
|
|
|
|
EVAL_EXPR(19, ((int)&*(char*)10 == 10 ? 1 : -1));
|
2009-02-22 02:14:20 +08:00
|
|
|
|
|
|
|
EVAL_EXPR(20, __builtin_constant_p(*((int*) 10), -1, 1));
|
2009-02-28 11:59:05 +08:00
|
|
|
|
|
|
|
EVAL_EXPR(21, (__imag__ 2i) == 2 ? 1 : -1);
|
|
|
|
|
|
|
|
EVAL_EXPR(22, (__real__ (2i+3)) == 3 ? 1 : -1);
|
|
|
|
|
2009-03-01 05:56:50 +08:00
|
|
|
int g23[(int)(1.0 / 1.0)] = { 1 };
|
|
|
|
int g24[(int)(1.0 / 1.0)] = { 1 , 2 }; // expected-warning {{excess elements in array initializer}}
|
|
|
|
int g25[(int)(1.0 + 1.0)], g26 = sizeof(g25);
|
2009-03-23 12:38:34 +08:00
|
|
|
|
|
|
|
EVAL_EXPR(26, (_Complex double)0 ? -1 : 1)
|
|
|
|
EVAL_EXPR(27, (_Complex int)0 ? -1 : 1)
|
|
|
|
EVAL_EXPR(28, (_Complex double)1 ? 1 : -1)
|
|
|
|
EVAL_EXPR(29, (_Complex int)1 ? 1 : -1)
|