Home | History | Annotate | Download | only in SemaCXX
      1 // RUN: %clang_cc1 -fsyntax-only -verify %s -triple=i686-pc-linux-gnu -std=c++11
      2 
      3 using size_t = decltype(sizeof(0));
      4 struct noreturn_t {} constexpr noreturn = {};
      5 
      6 void *operator new [[noreturn]] (size_t, noreturn_t);
      7 void operator delete [[noreturn]] (void*, noreturn_t);
      8 
      9 void good_news()
     10 {
     11   auto p = new int[2][[]];
     12   auto q = new int[[]][2];
     13   auto r = new int*[[]][2][[]];
     14   auto s = new (int(*[[]])[2][[]]);
     15 }
     16 
     17 void bad_news(int *ip)
     18 {
     19   // attribute-specifiers can go almost anywhere in a new-type-id...
     20   auto r = new int[[]{return 1;}()][2]; // expected-error {{expected ']'}}
     21   auto s = new int*[[]{return 1;}()][2]; // expected-error {{expected ']'}}
     22   // ... but not here:
     23   auto t = new (int(*)[[]]); // expected-error {{an attribute list cannot appear here}}
     24   auto u = new (int(*)[[]{return 1;}()][2]); // expected-error {{C++11 only allows consecutive left square brackets when introducing an attribute}} \
     25                                                 expected-error {{variably modified type}} \
     26                                                 expected-error {{a lambda expression may not appear inside of a constant expression}}
     27 }
     28 
     29 void good_deletes()
     30 {
     31   delete [&]{ return (int*)0; }();
     32 }
     33 
     34 void bad_deletes()
     35 {
     36   // 'delete []' is always array delete, per [expr.delete]p1.
     37   // FIXME: Give a better diagnostic.
     38   delete []{ return (int*)0; }(); // expected-error {{expected expression}}
     39 }
     40