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