blob: 6015e918a340e23b39cbfab59409a9f252aa9b37 [file] [log] [blame]
Douglas Gregor67ca40c2010-07-26 04:08:02 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
Chris Lattnere66218b2006-08-12 17:19:28 +00002
3void test1() {
Douglas Gregor67ca40c2010-07-26 04:08:02 +00004 if (sizeof (int){ 1}) {} // sizeof compound literal
5 if (sizeof (int)) {} // sizeof type
Chris Lattnere66218b2006-08-12 17:19:28 +00006
Douglas Gregor67ca40c2010-07-26 04:08:02 +00007 (void)(int)4; // cast.
8 (void)(int){4}; // compound literal.
Chris Lattnere66218b2006-08-12 17:19:28 +00009
Douglas Gregor67ca40c2010-07-26 04:08:02 +000010 int A = (struct{ int a;}){ 1}.a;
Chris Lattnere66218b2006-08-12 17:19:28 +000011}
12
13int test2(int a, int b) {
Douglas Gregor67ca40c2010-07-26 04:08:02 +000014 return a ? (void)a,b : a;
Chris Lattnere66218b2006-08-12 17:19:28 +000015}
16
Chris Lattner2c5c4212006-08-12 18:11:24 +000017int test3(int a, int b, int c) {
Chris Lattnere66218b2006-08-12 17:19:28 +000018 return a = b = c;
19}
Chris Lattner2c5c4212006-08-12 18:11:24 +000020
21int test4() {
22 test4();
Douglas Gregor67ca40c2010-07-26 04:08:02 +000023 return 0;
Chris Lattner2c5c4212006-08-12 18:11:24 +000024}
Chris Lattner5b6032a2006-08-12 19:15:40 +000025
Douglas Gregor67ca40c2010-07-26 04:08:02 +000026struct X0 { struct { struct { int c[10][9]; } b; } a; };
27
Chris Lattner5b6032a2006-08-12 19:15:40 +000028int test_offsetof() {
Douglas Gregor67ca40c2010-07-26 04:08:02 +000029 (void)__builtin_offsetof(struct X0, a.b.c[4][5]);
30 return 0;
Chris Lattner5b6032a2006-08-12 19:15:40 +000031}
Chris Lattner47791a42007-11-13 20:50:37 +000032
33void test_sizeof(){
34 int arr[10];
Douglas Gregor67ca40c2010-07-26 04:08:02 +000035 (void)sizeof arr[0];
36 (void)sizeof(arr[0]);
37 (void)sizeof(arr)[0];
Chris Lattner47791a42007-11-13 20:50:37 +000038}
39
Eli Friedmaneb3a9b02009-01-27 08:43:38 +000040// PR3418
41int test_leading_extension() {
Abramo Bagnara932e3932010-10-15 07:51:18 +000042 __extension__ (*(char*)0) = 1; // expected-warning {{indirection of non-volatile null pointer}} \
43 // expected-note {{consider using __builtin_trap}}
Douglas Gregor67ca40c2010-07-26 04:08:02 +000044 return 0;
Eli Friedmaneb3a9b02009-01-27 08:43:38 +000045}
Chris Lattner47791a42007-11-13 20:50:37 +000046
Chris Lattner0d6c0612009-04-13 00:10:38 +000047// PR3972
48int test5(int);
49int test6(void) {
50 return test5( // expected-note {{to match}}
51 test5(1)
52 ; // expected-error {{expected ')'}}
53}