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
good_news()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
bad_news(int * ip)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}} expected-error {{variably modified type}}
25 }
26
good_deletes()27 void good_deletes()
28 {
29 delete [&]{ return (int*)0; }();
30 }
31
bad_deletes()32 void bad_deletes()
33 {
34 // 'delete []' is always array delete, per [expr.delete]p1.
35 // FIXME: Give a better diagnostic.
36 delete []{ return (int*)0; }(); // expected-error {{expected expression}}
37 }
38