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