blob: 64b44470f7e745598d92cac9394b9d645d2a3826 [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}
John McCallc5e6b972011-04-06 02:35:25 +000054
55// PR8394
56void test7() {
57 ({} // expected-note {{to match}}
58 ; // expected-error {{expected ')'}}
59}
Serge Pavlovaa57a642013-10-08 16:56:30 +000060
61// PR16992
62struct pr16992 { int x; };
63
64void func_16992 () {
David Majnemer767c1f82013-10-09 00:22:23 +000065 int x1 = sizeof int; // expected-error {{expected parentheses around type name in sizeof expression}}
66 int x2 = sizeof struct pr16992; // expected-error {{expected parentheses around type name in sizeof expression}}
67 int x3 = __alignof int; // expected-error {{expected parentheses around type name in __alignof expression}}
68 int x4 = _Alignof int; // expected-error {{expected parentheses around type name in _Alignof expression}}
Serge Pavlovaa57a642013-10-08 16:56:30 +000069}
Kaelyn Takata22101f92014-07-14 22:48:10 +000070
71void callee(double, double);
72void test8() {
73 callee(foobar, // expected-error {{use of undeclared identifier 'foobar'}}
74 fizbin); // expected-error {{use of undeclared identifier 'fizbin'}}
75}