blob: 055f14bf4dc60b907b9bbd1358254f2f1f9a467f [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
Nuno Lopesf2319982009-02-02 15:00:55 +00002// PR3459
3struct bar {
Mike Stump1eb44332009-09-09 15:08:12 +00004 char n[1];
Nuno Lopesf2319982009-02-02 15:00:55 +00005};
6
7struct foo {
Mike Stump1eb44332009-09-09 15:08:12 +00008 char name[(int)&((struct bar *)0)->n];
Chris Lattnere1eed382011-06-14 06:38:10 +00009 char name2[(int)&((struct bar *)0)->n - 1]; //expected-error{{'name2' declared as an array with a negative size}}
Nuno Lopesf2319982009-02-02 15:00:55 +000010};
Douglas Gregor1931b442009-02-03 00:34:39 +000011
12// PR3430
13struct s {
Mike Stump1eb44332009-09-09 15:08:12 +000014 struct st {
15 int v;
16 } *ts;
Douglas Gregor1931b442009-02-03 00:34:39 +000017};
18
19struct st;
20
21int foo() {
Mike Stump1eb44332009-09-09 15:08:12 +000022 struct st *f;
23 return f->v + f[0].v;
Douglas Gregor1931b442009-02-03 00:34:39 +000024}
Eli Friedman85c35152009-02-22 00:20:44 +000025
Douglas Gregore4f3e062009-03-06 23:41:27 +000026// PR3642, PR3671
Eli Friedman85c35152009-02-22 00:20:44 +000027struct pppoe_tag {
28 short tag_type;
29 char tag_data[];
30};
31struct datatag {
Mike Stump1eb44332009-09-09 15:08:12 +000032 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 Friedman85c35152009-02-22 00:20:44 +000034};
35
Chris Lattner65e6a092009-04-29 05:12:23 +000036
37// PR4092
38struct s0 {
39 char a; // expected-note {{previous declaration is here}}
40 char a; // expected-error {{duplicate member 'a'}}
41};
42
43struct s0 f0(void) {}
Ted Kremenekcfd41cf2010-07-12 17:35:39 +000044
45// <rdar://problem/8177927> - This previously triggered an assertion failure.
46struct x0 {
47 unsigned int x1;
48};
John McCallac4df242011-03-22 23:00:04 +000049
50// rdar://problem/9150338
51static struct test1 { // expected-warning {{'static' ignored on this declaration}}
52 int x;
53};
54const struct test2 { // expected-warning {{'const' ignored on this declaration}}
55 int x;
56};
Richard Smithc7f81162013-03-18 22:52:47 +000057inline struct test3 { // expected-error {{'inline' can only appear on functions}}
John McCallac4df242011-03-22 23:00:04 +000058 int x;
59};
Richard Smitha41c97a2013-09-20 01:15:31 +000060
61struct hiding_1 {};
62struct hiding_2 {};
63void 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 Hines6bcf27b2014-05-29 04:14:42 -070069
70struct PreserveAttributes {};
71typedef struct __attribute__((noreturn)) PreserveAttributes PreserveAttributes_t; // expected-warning {{'noreturn' attribute only applies to functions and methods}}