102 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -verify %s 2// pr70293 4template <class Key, class T> struct QMap5{6 void insert(const Key &, const T &);7 T v;8};9 10 11template <class Key, class T>12void QMap<Key, T>::insert(const Key &, const T &avalue)13{14 v = avalue;15}16 17struct 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;23 24struct inotify_event25{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 34void 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 44struct S {45 virtual void foo();46};47 48struct X {49 int blah;50 S strings[];51};52 53S a, b = a;54S f(X &x) {55 a = b;56 return x.strings[0];57}58 59class A {60 int s;61 char c[];62};63 64union B {65 int s;66 char c[];67};68 69class C {70 char c[]; // expected-error {{flexible array member 'c' with type 'char[]' is not at the end of class}}71 int s; // expected-note {{next field declaration is here}}72};73 74namespace rdar9065507 {75 76struct StorageBase {77 long ref_count;78 unsigned size;79 unsigned capacity;80};81 82struct Storage : StorageBase {83 int data[];84};85 86struct VirtStorage : virtual StorageBase {87 int data[]; // expected-error {{flexible array member 'data' not allowed in struct which has a virtual base class}}88};89 90}91 92struct NonTrivDtor { ~NonTrivDtor(); };93// FIXME: It's not clear whether we should disallow examples like this. GCC accepts.94struct FlexNonTrivDtor {95 int n;96 NonTrivDtor ntd[]; // expected-error {{flexible array member 'ntd' of type 'NonTrivDtor[]' with non-trivial destruction}}97 ~FlexNonTrivDtor() {98 for (int i = n; i != 0; --i)99 ntd[i-1].~NonTrivDtor();100 }101};102