annotate clang/test/SemaCXX/new-delete-0x.cpp @ 150:1d019706d866

LLVM10
author anatofuz
date Thu, 13 Feb 2020 15:10:13 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clang_cc1 -fsyntax-only -verify %s -triple=i686-pc-linux-gnu -std=c++11
anatofuz
parents:
diff changeset
2
anatofuz
parents:
diff changeset
3 using size_t = decltype(sizeof(0));
anatofuz
parents:
diff changeset
4 struct noreturn_t {} constexpr noreturn = {};
anatofuz
parents:
diff changeset
5
anatofuz
parents:
diff changeset
6 void *operator new [[noreturn]] (size_t, noreturn_t);
anatofuz
parents:
diff changeset
7 void operator delete [[noreturn]] (void*, noreturn_t);
anatofuz
parents:
diff changeset
8
anatofuz
parents:
diff changeset
9 void good_news()
anatofuz
parents:
diff changeset
10 {
anatofuz
parents:
diff changeset
11 auto p = new int[2][[]];
anatofuz
parents:
diff changeset
12 auto q = new int[[]][2];
anatofuz
parents:
diff changeset
13 auto r = new int*[[]][2][[]];
anatofuz
parents:
diff changeset
14 auto s = new (int(*[[]])[2][[]]);
anatofuz
parents:
diff changeset
15 }
anatofuz
parents:
diff changeset
16
anatofuz
parents:
diff changeset
17 void bad_news(int *ip)
anatofuz
parents:
diff changeset
18 {
anatofuz
parents:
diff changeset
19 // attribute-specifiers can go almost anywhere in a new-type-id...
anatofuz
parents:
diff changeset
20 auto r = new int[[]{return 1;}()][2]; // expected-error {{expected ']'}}
anatofuz
parents:
diff changeset
21 auto s = new int*[[]{return 1;}()][2]; // expected-error {{expected ']'}}
anatofuz
parents:
diff changeset
22 // ... but not here:
anatofuz
parents:
diff changeset
23 auto t = new (int(*)[[]]); // expected-error {{an attribute list cannot appear here}}
anatofuz
parents:
diff changeset
24 auto u = new (int(*)[[]{return 1;}()][2]); // expected-error {{C++11 only allows consecutive left square brackets when introducing an attribute}} \
anatofuz
parents:
diff changeset
25 expected-error {{variably modified type}} \
anatofuz
parents:
diff changeset
26 expected-error {{a lambda expression may not appear inside of a constant expression}}
anatofuz
parents:
diff changeset
27 }
anatofuz
parents:
diff changeset
28
anatofuz
parents:
diff changeset
29 void good_deletes()
anatofuz
parents:
diff changeset
30 {
anatofuz
parents:
diff changeset
31 delete [&]{ return (int*)0; }();
anatofuz
parents:
diff changeset
32 }
anatofuz
parents:
diff changeset
33
anatofuz
parents:
diff changeset
34 void bad_deletes()
anatofuz
parents:
diff changeset
35 {
anatofuz
parents:
diff changeset
36 // 'delete []' is always array delete, per [expr.delete]p1.
anatofuz
parents:
diff changeset
37 delete []{ return (int*)0; }(); // expected-error {{'[]' after delete interpreted as 'delete[]'}}
anatofuz
parents:
diff changeset
38 }