brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.8 KiB · aa9ce37 Raw
42 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -verify %s -triple=i686-pc-linux-gnu -std=c++112// RUN: %clang_cc1 -fsyntax-only -verify %s -triple=i686-pc-linux-gnu -std=c++11 -fexperimental-new-constant-interpreter3 4using size_t = decltype(sizeof(0));5struct noreturn_t {} constexpr noreturn = {};6 7void *operator new [[noreturn]] (size_t, noreturn_t);8void operator delete [[noreturn]] (void*, noreturn_t);9 10void 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 18void 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 32void good_deletes()33{34  delete [&]{ return (int*)0; }();35}36 37void 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}42