| Fariborz Jahanian | 1138ba6 | 2010-05-26 20:19:07 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
| 2 | // pr7029 |
| 3 | |
| 4 | template <class Key, class T> struct QMap |
| 5 | { |
| 6 | void insert(const Key &, const T &); |
| 7 | T v; |
| 8 | }; |
| 9 | |
| 10 | |
| 11 | template <class Key, class T> |
| 12 | void QMap<Key, T>::insert(const Key &, const T &avalue) |
| 13 | { |
| 14 | v = avalue; |
| 15 | } |
| 16 | |
| David Majnemer | ac0b30e | 2014-09-24 11:04:09 +0000 | [diff] [blame^] | 17 | struct Rec { |
| 18 | union { // expected-warning-re {{variable sized type '{{.*}}' not at the end of a struct or class is a GNU extension}} |
| 19 | int u0[]; |
| 20 | }; |
| 21 | int x; |
| 22 | } rec; |
| Fariborz Jahanian | 1138ba6 | 2010-05-26 20:19:07 +0000 | [diff] [blame] | 23 | |
| 24 | struct inotify_event |
| 25 | { |
| 26 | int wd; |
| 27 | |
| 28 | // clang doesn't like '[]': |
| 29 | // cannot initialize a parameter of type 'void *' with an rvalue of type 'char (*)[]' |
| 30 | char name []; |
| 31 | }; |
| 32 | |
| 33 | |
| 34 | void foo() |
| 35 | { |
| 36 | inotify_event event; |
| 37 | inotify_event* ptr = &event; |
| 38 | inotify_event event1 = *ptr; |
| 39 | *ptr = event; |
| 40 | QMap<int, inotify_event> eventForId; |
| 41 | eventForId.insert(ptr->wd, *ptr); |
| 42 | } |
| 43 | |
| 44 | struct S { |
| Richard Smith | 6fa28ff | 2014-01-11 00:53:35 +0000 | [diff] [blame] | 45 | virtual void foo(); |
| Fariborz Jahanian | 1138ba6 | 2010-05-26 20:19:07 +0000 | [diff] [blame] | 46 | }; |
| 47 | |
| 48 | struct X { |
| 49 | int blah; |
| Richard Smith | 6fa28ff | 2014-01-11 00:53:35 +0000 | [diff] [blame] | 50 | S strings[]; |
| Fariborz Jahanian | 1138ba6 | 2010-05-26 20:19:07 +0000 | [diff] [blame] | 51 | }; |
| Anders Carlsson | f849774 | 2010-09-03 21:53:49 +0000 | [diff] [blame] | 52 | |
| Richard Smith | 6fa28ff | 2014-01-11 00:53:35 +0000 | [diff] [blame] | 53 | S a, b = a; |
| 54 | S f(X &x) { |
| 55 | a = b; |
| 56 | return x.strings[0]; |
| 57 | } |
| 58 | |
| Anders Carlsson | f849774 | 2010-09-03 21:53:49 +0000 | [diff] [blame] | 59 | class A { |
| 60 | int s; |
| 61 | char c[]; |
| 62 | }; |
| 63 | |
| 64 | union B { |
| 65 | int s; |
| Argyrios Kyrtzidis | 7e25a95 | 2011-03-07 20:04:04 +0000 | [diff] [blame] | 66 | char c[]; |
| Anders Carlsson | f849774 | 2010-09-03 21:53:49 +0000 | [diff] [blame] | 67 | }; |
| Argyrios Kyrtzidis | 7e25a95 | 2011-03-07 20:04:04 +0000 | [diff] [blame] | 68 | |
| 69 | namespace rdar9065507 { |
| 70 | |
| 71 | struct StorageBase { |
| 72 | long ref_count; |
| 73 | unsigned size; |
| 74 | unsigned capacity; |
| 75 | }; |
| 76 | |
| 77 | struct Storage : StorageBase { |
| 78 | int data[]; |
| 79 | }; |
| 80 | |
| David Majnemer | 08cd760 | 2013-11-02 11:19:13 +0000 | [diff] [blame] | 81 | struct VirtStorage : virtual StorageBase { |
| 82 | int data[]; // expected-error {{flexible array member 'data' not allowed in struct which has a virtual base class}} |
| 83 | }; |
| 84 | |
| Argyrios Kyrtzidis | 7e25a95 | 2011-03-07 20:04:04 +0000 | [diff] [blame] | 85 | } |
| Richard Smith | 6fa28ff | 2014-01-11 00:53:35 +0000 | [diff] [blame] | 86 | |
| 87 | struct NonTrivDtor { ~NonTrivDtor(); }; |
| 88 | // FIXME: It's not clear whether we should disallow examples like this. GCC accepts. |
| 89 | struct FlexNonTrivDtor { |
| 90 | int n; |
| 91 | NonTrivDtor ntd[]; // expected-error {{flexible array member 'ntd' of type 'NonTrivDtor []' with non-trivial destruction}} |
| 92 | ~FlexNonTrivDtor() { |
| 93 | for (int i = n; i != 0; --i) |
| 94 | ntd[i-1].~NonTrivDtor(); |
| 95 | } |
| 96 | }; |