Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
Nuno Lopes | f231998 | 2009-02-02 15:00:55 +0000 | [diff] [blame] | 2 | // PR3459 |
| 3 | struct bar { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4 | char n[1]; |
Nuno Lopes | f231998 | 2009-02-02 15:00:55 +0000 | [diff] [blame] | 5 | }; |
| 6 | |
| 7 | struct foo { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8 | char name[(int)&((struct bar *)0)->n]; |
Chris Lattner | e1eed38 | 2011-06-14 06:38:10 +0000 | [diff] [blame] | 9 | char name2[(int)&((struct bar *)0)->n - 1]; //expected-error{{'name2' declared as an array with a negative size}} |
Nuno Lopes | f231998 | 2009-02-02 15:00:55 +0000 | [diff] [blame] | 10 | }; |
Douglas Gregor | 1931b44 | 2009-02-03 00:34:39 +0000 | [diff] [blame] | 11 | |
| 12 | // PR3430 |
| 13 | struct s { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 14 | struct st { |
| 15 | int v; |
| 16 | } *ts; |
Douglas Gregor | 1931b44 | 2009-02-03 00:34:39 +0000 | [diff] [blame] | 17 | }; |
| 18 | |
| 19 | struct st; |
| 20 | |
| 21 | int foo() { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 22 | struct st *f; |
| 23 | return f->v + f[0].v; |
Douglas Gregor | 1931b44 | 2009-02-03 00:34:39 +0000 | [diff] [blame] | 24 | } |
Eli Friedman | 85c3515 | 2009-02-22 00:20:44 +0000 | [diff] [blame] | 25 | |
Douglas Gregor | e4f3e06 | 2009-03-06 23:41:27 +0000 | [diff] [blame] | 26 | // PR3642, PR3671 |
Eli Friedman | 85c3515 | 2009-02-22 00:20:44 +0000 | [diff] [blame] | 27 | struct pppoe_tag { |
| 28 | short tag_type; |
| 29 | char tag_data[]; |
| 30 | }; |
| 31 | struct datatag { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 32 | struct pppoe_tag hdr; //expected-warning{{field 'hdr' with variable sized type 'struct pppoe_tag' not at the end of a struct or class is a GNU extension}} |
| 33 | char data; |
Eli Friedman | 85c3515 | 2009-02-22 00:20:44 +0000 | [diff] [blame] | 34 | }; |
| 35 | |
Chris Lattner | 65e6a09 | 2009-04-29 05:12:23 +0000 | [diff] [blame] | 36 | |
| 37 | // PR4092 |
| 38 | struct s0 { |
| 39 | char a; // expected-note {{previous declaration is here}} |
| 40 | char a; // expected-error {{duplicate member 'a'}} |
| 41 | }; |
| 42 | |
| 43 | struct s0 f0(void) {} |
Ted Kremenek | cfd41cf | 2010-07-12 17:35:39 +0000 | [diff] [blame] | 44 | |
| 45 | // <rdar://problem/8177927> - This previously triggered an assertion failure. |
| 46 | struct x0 { |
| 47 | unsigned int x1; |
| 48 | }; |
John McCall | ac4df24 | 2011-03-22 23:00:04 +0000 | [diff] [blame] | 49 | |
| 50 | // rdar://problem/9150338 |
| 51 | static struct test1 { // expected-warning {{'static' ignored on this declaration}} |
| 52 | int x; |
| 53 | }; |
| 54 | const struct test2 { // expected-warning {{'const' ignored on this declaration}} |
| 55 | int x; |
| 56 | }; |
Richard Smith | c7f8116 | 2013-03-18 22:52:47 +0000 | [diff] [blame] | 57 | inline struct test3 { // expected-error {{'inline' can only appear on functions}} |
John McCall | ac4df24 | 2011-03-22 23:00:04 +0000 | [diff] [blame] | 58 | int x; |
| 59 | }; |
Richard Smith | a41c97a | 2013-09-20 01:15:31 +0000 | [diff] [blame] | 60 | |
| 61 | struct hiding_1 {}; |
| 62 | struct hiding_2 {}; |
| 63 | void test_hiding() { |
| 64 | struct hiding_1 *hiding_1(); |
| 65 | extern struct hiding_2 *hiding_2; |
| 66 | struct hiding_1 *p = hiding_1(); |
| 67 | struct hiding_2 *q = hiding_2; |
| 68 | } |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 69 | |
| 70 | struct PreserveAttributes {}; |
| 71 | typedef struct __attribute__((noreturn)) PreserveAttributes PreserveAttributes_t; // expected-warning {{'noreturn' attribute only applies to functions and methods}} |