Home | History | Annotate | Download | only in SemaCXX
      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 
     17 
     18 struct inotify_event
     19 {
     20   int wd;
     21 
     22   // clang doesn't like '[]':
     23   // cannot initialize a parameter of type 'void *' with an rvalue of type 'char (*)[]'
     24   char name [];
     25 };
     26 
     27 
     28 void foo()
     29 {
     30     inotify_event event;
     31     inotify_event* ptr = &event;
     32     inotify_event event1 = *ptr;
     33     *ptr = event;
     34     QMap<int, inotify_event> eventForId;
     35     eventForId.insert(ptr->wd, *ptr);
     36 }
     37 
     38 struct S {
     39   virtual void foo();
     40 };
     41 
     42 struct X {
     43    int blah;
     44    S strings[];
     45 };
     46 
     47 S a, b = a;
     48 S f(X &x) {
     49   a = b;
     50   return x.strings[0];
     51 }
     52 
     53 class A {
     54   int s;
     55   char c[];
     56 };
     57 
     58 union B {
     59   int s;
     60   char c[];
     61 };
     62 
     63 namespace rdar9065507 {
     64 
     65 struct StorageBase {
     66   long ref_count;
     67   unsigned size;
     68   unsigned capacity;
     69 };
     70 
     71 struct Storage : StorageBase {
     72   int data[];
     73 };
     74 
     75 struct VirtStorage : virtual StorageBase {
     76   int data[]; // expected-error {{flexible array member 'data' not allowed in struct which has a virtual base class}}
     77 };
     78 
     79 }
     80 
     81 struct NonTrivDtor { ~NonTrivDtor(); };
     82 // FIXME: It's not clear whether we should disallow examples like this. GCC accepts.
     83 struct FlexNonTrivDtor {
     84   int n;
     85   NonTrivDtor ntd[]; // expected-error {{flexible array member 'ntd' of type 'NonTrivDtor []' with non-trivial destruction}}
     86   ~FlexNonTrivDtor() {
     87     for (int i = n; i != 0; --i)
     88       ntd[i-1].~NonTrivDtor();
     89   }
     90 };
     91