Debian Codegraph @

clang/test/SemaCXX/new-delete.cpp

raw
1 // RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx98-23,precxx20 %s -triple=i686-pc-linux-gnu -Wno-new-returns-null -std=c++98
2 // RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx98-23,precxx20 %s -triple=i686-pc-linux-gnu -Wno-new-returns-null -std=c++11
3 // RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx98-23,precxx20 %s -triple=i686-pc-linux-gnu -Wno-new-returns-null -std=c++14
4 // RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx98-23,cxx17,precxx20 %s -triple=i686-pc-linux-gnu -Wno-new-returns-null -std=c++17
5 // RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx98-23,cxx17,cxx20 %s -triple=i686-pc-linux-gnu -Wno-new-returns-null -std=c++20
6 // RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx98-23,cxx17,cxx20 %s -triple=i686-pc-linux-gnu -Wno-new-returns-null -std=c++23
7 // RUN: %clang_cc1 -fsyntax-only -verify=expected,since-cxx26,cxx17,cxx20 %s -triple=i686-pc-linux-gnu -Wno-new-returns-null -std=c++2c
8
9 // RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx98-23,precxx20 %s -triple=i686-pc-linux-gnu -Wno-new-returns-null -std=c++98 -fexperimental-new-constant-interpreter -DNEW_INTERP
10 // RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx98-23,precxx20 %s -triple=i686-pc-linux-gnu -Wno-new-returns-null -std=c++11 -fexperimental-new-constant-interpreter -DNEW_INTERP
11 // RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx98-23,precxx20 %s -triple=i686-pc-linux-gnu -Wno-new-returns-null -std=c++14 -fexperimental-new-constant-interpreter -DNEW_INTERP
12 // RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx98-23,cxx17,precxx20 %s -triple=i686-pc-linux-gnu -Wno-new-returns-null -std=c++17 -fexperimental-new-constant-interpreter -DNEW_INTERP
13 // RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx98-23,cxx17,cxx20 %s -triple=i686-pc-linux-gnu -Wno-new-returns-null -std=c++20 -fexperimental-new-constant-interpreter -DNEW_INTERP
14 // RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx98-23,cxx17,cxx20 %s -triple=i686-pc-linux-gnu -Wno-new-returns-null -std=c++23 -fexperimental-new-constant-interpreter -DNEW_INTERP
15 // RUN: %clang_cc1 -fsyntax-only -verify=expected,since-cxx26,cxx17,cxx20 %s -triple=i686-pc-linux-gnu -Wno-new-returns-null -std=c++2c -fexperimental-new-constant-interpreter -DNEW_INTERP
16
17 // FIXME Location is (frontend)
18 // cxx17-note@*:* {{candidate function not viable: requires 2 arguments, but 3 were provided}}
19
20 #include <stddef.h>
21
22 #if __cplusplus >= 201103L
23 // expected-note@+2 {{candidate constructor (the implicit move constructor) not viable}}
24 #endif
25 struct S // expected-note {{candidate}}
26 {
27 S(int, int, double); // expected-note {{candidate}}
28 S(double, int); // expected-note 2 {{candidate}}
29 S(float, int); // expected-note 2 {{candidate}}
30 };
31 struct T; // expected-note{{forward declaration of 'T'}}
32 struct U
33 {
34 // A special new, to verify that the global version isn't used.
35 void* operator new(size_t, S*); // expected-note {{candidate}}
36 };
37 struct V : U
38 {
39 };
40 struct W // cxx20-note 2{{candidate constructor}}
41 {
42 int a;
43 int b;
44 };
45
46 inline void operator delete(void *); // expected-warning {{replacement function 'operator delete' cannot be declared 'inline'}}
47
48 __attribute__((used))
49 inline void *operator new(size_t) { // no warning, due to __attribute__((used))
50 return 0; // expected-warning {{null returned from function that requires a non-null return value}}
51 }
52
53 // PR5823
54 void* operator new(const size_t); // expected-note {{candidate}}
55 void* operator new(size_t, int*); // expected-note 2{{candidate}}
56 void* operator new(size_t, float*); // expected-note 2{{candidate}}
57 void* operator new(size_t, S); // expected-note {{candidate}}
58
59 struct foo { };
60
61 void good_news()
62 {
63 int *pi = new int;
64 float *pf = new (pi) float();
65 pi = new int(1);
66 pi = new int('c');
67 const int *pci = new const int();
68 S *ps = new S(1, 2, 3.4);
69 ps = new (pf) (S)(1, 2, 3.4);
70 S *(*paps)[2] = new S*[*pi][2];
71 typedef int ia4[4];
72 ia4 *pai = new (int[3][4]);
73 pi = ::new int;
74 U *pu = new (ps) U;
75 V *pv = new (ps) V;
76
77 pi = new (S(1.0f, 2)) int;
78
79 (void)new int[true];
80
81 // PR7147
82 typedef int a[2];
83 foo* f1 = new foo;
84 foo* f2 = new foo[2];
85 typedef foo x[2];
86 typedef foo y[2][2];
87 x* f3 = new y;
88
89 #if __cplusplus >= 201103L
90 (void)new int[]{};
91 (void)new int[]{1, 2, 3};
92 (void)new char[]{"hello"};
93 #endif
94 }
95
96 struct abstract {
97 virtual ~abstract() = 0;
98 };
99
100 void bad_news(int *ip)
101 {
102 int i = 1; // expected-note 2{{here}}
103 (void)new; // expected-error {{expected a type}}
104 (void)new 4; // expected-error {{expected a type}}
105 (void)new () int; // expected-error {{expected expression}}
106 (void)new int[1.1];
107 #if __cplusplus <= 199711L
108 // expected-error@-2 {{array size expression must have integral or enumeration type, not 'double'}}
109 #elif __cplusplus <= 201103L
110 // expected-error@-4 {{array size expression must have integral or unscoped enumeration type, not 'double'}}
111 #else
112 // expected-warning@-6 {{implicit conversion from 'double' to 'unsigned int' changes value from 1.1 to 1}}
113 #endif
114
115 (void)new int[1][i]; // expected-note {{read of non-const variable 'i' is not allowed in a constant expression}}
116 (void)new (int[1][i]); // expected-note {{read of non-const variable 'i' is not allowed in a constant expression}}
117 #if __cplusplus <= 201103L
118 // expected-error@-3 {{only the first dimension}}
119 // expected-error@-3 {{only the first dimension}}
120 #else
121 // expected-error@-6 {{array size is not a constant expression}}
122 // expected-error@-6 {{array size is not a constant expression}}
123 #endif
124 (void)new (int[i]); // expected-warning {{when type is in parentheses}}
125 (void)new int(*(S*)0); // expected-error {{no viable conversion from 'S' to 'int'}}
126 (void)new int(1, 2); // expected-error {{excess elements in scalar initializer}}
127 (void)new S(1); // expected-error {{no matching constructor}}
128 (void)new S(1, 1); // expected-error {{call to constructor of 'S' is ambiguous}}
129 (void)new const int; // expected-error {{default initialization of an object of const type 'const int'}}
130 (void)new float*(ip); // expected-error {{cannot initialize a new value of type 'float *' with an lvalue of type 'int *'}}
131 // Undefined, but clang should reject it directly.
132 (void)new int[-1];
133 #if __cplusplus <= 201103L
134 // expected-error@-2 {{array size is negative}}
135 #else
136 // expected-error@-4 {{array is too large}}
137 #endif
138 (void)new int[2000000000]; // expected-error {{array is too large}}
139 (void)new int[*(S*)0];
140 #if __cplusplus <= 199711L
141 // expected-error@-2 {{array size expression must have integral or enumeration type, not 'S'}}
142 #elif __cplusplus <= 201103L
143 // expected-error@-4 {{array size expression must have integral or unscoped enumeration type, not 'S'}}
144 #else
145 // expected-error@-6 {{converting 'S' to incompatible type}}
146 #endif
147
148 (void)::S::new int; // expected-error {{expected unqualified-id}}
149 (void)new (0, 0) int; // expected-error {{no matching function for call to 'operator new'}}
150 (void)new (0L) int; // expected-error {{call to 'operator new' is ambiguous}}
151 // This must fail, because the member version shouldn't be found.
152 (void)::new ((S*)0) U; // expected-error {{no matching 'operator new' function for non-allocating placement new expression; include <new>}}
153 // This must fail, because any member version hides all global versions.
154 (void)new U; // expected-error {{no matching function for call to 'operator new'}}
155 (void)new (int[]); // expected-error {{array size must be specified in new expression with no initializer}}
156 (void)new int&; // expected-error {{cannot allocate reference type 'int &' with new}}
157 (void)new int[]; // expected-error {{array size must be specified in new expression with no initializer}}
158 (void)new int[](); // expected-error {{cannot determine allocated array size from initializer}}
159 // FIXME: This is a terrible diagnostic.
160 #if __cplusplus < 201103L
161 (void)new int[]{}; // expected-error {{array size must be specified in new expression with no initializer}}
162 #endif
163 }
164
165 void no_matching_placement_new() {
166 struct X { int n; };
167 __attribute__((aligned(__alignof(X)))) unsigned char buffer[sizeof(X)];
168 (void)new(buffer) X; // expected-error {{no matching 'operator new' function for non-allocating placement new expression; include <new>}}
169 (void)new(+buffer) X; // expected-error {{no matching 'operator new' function for non-allocating placement new expression; include <new>}}
170 (void)new(&buffer) X; // expected-error {{no matching 'operator new' function for non-allocating placement new expression; include <new>}}
171 }
172
173 void good_deletes()
174 {
175 delete (int*)0;
176 delete [](int*)0;
177 delete (S*)0;
178 ::delete (int*)0;
179 }
180
181 void bad_deletes()
182 {
183 delete 0; // expected-error {{cannot delete expression of type 'int'}}
184 delete [0] (int*)0; // expected-error {{expected variable name or 'this' in lambda capture list}}
185 delete (void*)0;
186 // cxx98-23-warning@-1 {{cannot delete expression with pointer-to-'void' type 'void *'}}
187 // since-cxx26-error@-2 {{cannot delete pointer to incomplete type 'void'}}
188 delete (T*)0;
189 // cxx98-23-warning@-1 {{deleting pointer to incomplete type}}
190 // since-cxx26-error@-2 {{cannot delete pointer to incomplete type 'T'}}
191 ::S::delete (int*)0; // expected-error {{expected unqualified-id}}
192 }
193
194 struct X0 { };
195
196 struct X1 {
197 operator int*();
198 operator float();
199 };
200
201 struct X2 {
202 operator int*(); // expected-note {{conversion}}
203 operator float*(); // expected-note {{conversion}}
204 };
205
206 void test_delete_conv(X0 x0, X1 x1, X2 x2) {
207 delete x0; // expected-error{{cannot delete}}
208 delete x1;
209 delete x2; // expected-error{{ambiguous conversion of delete expression of type 'X2' to a pointer}}
210 }
211
212 // PR4782
213 class X3 {
214 public:
215 static void operator delete(void * mem, size_t size);
216 };
217
218 class X4 {
219 public:
220 static void release(X3 *x);
221 static void operator delete(void * mem, size_t size);
222 };
223
224
225 void X4::release(X3 *x) {
226 delete x;
227 }
228
229 class X5 {
230 public:
231 void Destroy() const { delete this; }
232 };
233
234 class Base {
235 public:
236 static void *operator new(signed char) throw(); // expected-error {{'operator new' takes type size_t}}
237 static int operator new[] (size_t) throw(); // expected-error {{operator new[]' must return type 'void *'}}
238 };
239
240 class Tier {};
241 class Comp : public Tier {};
242
243 class Thai : public Base {
244 public:
245 Thai(const Tier *adoptDictionary);
246 };
247
248 void loadEngineFor() {
249 const Comp *dict;
250 new Thai(dict);
251 }
252
253 template <class T> struct TBase {
254 void* operator new(T size, int); // expected-error {{'operator new' cannot take a dependent type as first parameter; use size_t}}
255 };
256
257 TBase<int> t1;
258
259 class X6 {
260 public:
261 static void operator delete(void*, int); // expected-note {{member found by ambiguous name lookup}}
262 };
263
264 class X7 {
265 public:
266 static void operator delete(void*, int); // expected-note {{member found by ambiguous name lookup}}
267 };
268
269 class X8 : public X6, public X7 {
270 };
271
272 void f(X8 *x8) {
273 delete x8; // expected-error {{member 'operator delete' found in multiple base classes of different types}}
274 }
275
276 class X9 {
277 public:
278 static void operator delete(void*, int); // expected-note {{'operator delete' declared here}}
279 static void operator delete(void*, float); // expected-note {{'operator delete' declared here}}
280 };
281
282 void f(X9 *x9) {
283 delete x9; // expected-error {{no suitable member 'operator delete' in 'X9'}}
284 }
285
286 struct X10 {
287 virtual ~X10();
288 #if __cplusplus >= 201103L
289 // expected-note@-2 {{overridden virtual function is here}}
290 #endif
291 };
292
293 struct X11 : X10 {
294 #if __cplusplus <= 199711L
295 // expected-error@-2 {{no suitable member 'operator delete' in 'X11'}}
296 #else
297 // expected-error@-4 {{deleted function '~X11' cannot override a non-deleted function}}
298 // expected-note@-5 2 {{virtual destructor requires an unambiguous, accessible 'operator delete'}}
299 #endif
300 void operator delete(void*, int);
301 #if __cplusplus <= 199711L
302 // expected-note@-2 {{'operator delete' declared here}}
303 #endif
304 };
305
306 void f() {
307 X11 x11;
308 #if __cplusplus <= 199711L
309 // expected-note@-2 {{implicit destructor for 'X11' first required here}}
310 #else
311 // expected-error@-4 {{attempt to use a deleted function}}
312 #endif
313 }
314
315 struct X12 {
316 void* operator new(size_t, void*);
317 };
318
319 struct X13 : X12 {
320 using X12::operator new;
321 };
322
323 static void* f(void* g)
324 {
325 return new (g) X13();
326 }
327
328 class X14 {
329 public:
330 static void operator delete(void*, const size_t);
331 };
332
333 void f(X14 *x14a, X14 *x14b) {
334 delete x14a;
335 }
336
337 class X15 {
338 private:
339 X15(); // expected-note {{declared private here}}
340 ~X15(); // expected-note {{declared private here}}
341 };
342
343 void f(X15* x) {
344 new X15(); // expected-error {{calling a private constructor}}
345 delete x; // expected-error {{calling a private destructor}}
346 }
347
348 namespace PR5918 { // Look for template operator new overloads.
349 struct S { template<typename T> static void* operator new(size_t, T); };
350 void test() {
351 (void)new(0) S;
352 }
353 }
354
355 namespace Test1 {
356
357 void f() {
358 (void)new int[10](1, 2); // precxx20-error {{array 'new' cannot have initialization arguments}}
359
360 typedef int T[10];
361 (void)new T(1, 2); // precxx20-error {{array 'new' cannot have initialization arguments}}
362 }
363
364 template<typename T>
365 void g(unsigned i) {
366 (void)new T[1](i); // precxx20-error {{array 'new' cannot have initialization arguments}}
367 }
368
369 template<typename T>
370 void h(unsigned i) {
371 (void)new T(i); // precxx20-error {{array 'new' cannot have initialization arguments}}
372 }
373 template void h<unsigned>(unsigned);
374 template void h<unsigned[10]>(unsigned); // precxx20-note {{in instantiation of function template specialization 'Test1::h<unsigned int[10]>' requested here}}
375
376 void i() {
377 new W[2](1, 2, 3); // precxx20-error {{array 'new' cannot have initialization arguments}}
378 // cxx20-error@-1 {{no viable conversion from 'int' to 'W'}}
379 }
380
381 }
382
383 // Don't diagnose access for overload candidates that aren't selected.
384 namespace PR7436 {
385 struct S1 {
386 void* operator new(size_t);
387 void operator delete(void* p);
388
389 private:
390 void* operator new(size_t, void*); // expected-note {{declared private here}}
391 void operator delete(void*, void*);
392 };
393 class S2 {
394 void* operator new(size_t); // expected-note {{declared private here}}
395 void operator delete(void* p); // expected-note {{declared private here}}
396 };
397
398 void test(S1* s1, S2* s2) {
399 delete s1;
400 delete s2; // expected-error {{is a private member}}
401 (void)new S1();
402 (void)new (0L) S1(); // expected-error {{is a private member}}
403 (void)new S2(); // expected-error {{is a private member}}
404 }
405 }
406
407 namespace rdar8018245 {
408 struct X0 {
409 static const int value = 17;
410 };
411
412 const int X0::value;
413
414 struct X1 {
415 static int value;
416 };
417
418 int X1::value;
419
420 template<typename T>
421 int *f() {
422 return new (int[T::value]); // expected-warning{{when type is in parentheses, array cannot have dynamic size}}
423 }
424
425 template int *f<X0>();
426 template int *f<X1>(); // expected-note{{in instantiation of}}
427
428 }
429
430 namespace Instantiate {
431 template<typename T> struct X {
432 operator T*();
433 };
434
435 void f(X<int> &xi) {
436 delete xi;
437 }
438 }
439
440 namespace PR7810 {
441 struct X {
442 // cv is ignored in arguments
443 static void operator delete(void *const);
444 };
445 struct Y {
446 // cv is ignored in arguments
447 #if __cplusplus < 202002L
448 static void operator delete(void *volatile);
449 #else
450 static void operator delete(void *);
451 #endif
452 };
453 }
454
455 // Don't crash on template delete operators
456 namespace TemplateDestructors {
457 struct S {
458 virtual ~S() {}
459
460 void* operator new(const size_t size);
461 template<class T> void* operator new(const size_t, const int, T*);
462 void operator delete(void*, const size_t);
463 template<class T> void operator delete(void*, const size_t, const int, T*);
464 };
465 }
466
467 namespace DeleteParam {
468 struct X {
469 void operator delete(X*); // expected-error{{first parameter of 'operator delete' must have type 'void *'}}
470 };
471
472 struct Y {
473 void operator delete(void* const);
474 };
475 }
476
477 // Test that the correct 'operator delete' is selected to pair with
478 // the unexpected placement 'operator new'.
479 namespace PairedDelete {
480 template <class T> struct A {
481 A();
482 void *operator new(size_t s, double d = 0);
483 void operator delete(void *p, double d);
484 void operator delete(void *p) {
485 T::dealloc(p);
486 }
487 };
488
489 A<int> *test() {
490 return new A<int>();
491 }
492 }
493
494 namespace PR7702 {
495 void test1() {
496 new DoesNotExist; // expected-error {{unknown type name 'DoesNotExist'}}
497 }
498 }
499
500 namespace ArrayNewNeedsDtor {
501 struct A { A(); private: ~A(); };
502 #if __cplusplus <= 199711L
503 // expected-note@-2 {{declared private here}}
504 #endif
505 struct B { B(); A a; };
506 #if __cplusplus <= 199711L
507 // expected-error@-2 {{field of type 'A' has private destructor}}
508 #else
509 // expected-note@-4 {{destructor of 'B' is implicitly deleted because field 'a' has an inaccessible destructor}}
510 #endif
511
512 B *test9() {
513 return new B[5];
514 #if __cplusplus <= 199711L
515 // expected-note@-2 {{implicit destructor for 'ArrayNewNeedsDtor::B' first required here}}
516 #else
517 // expected-error@-4 {{attempt to use a deleted function}}
518 #endif
519 }
520 }
521
522 namespace DeleteIncompleteClass {
523 struct A; // expected-note {{forward declaration}}
524 extern A x;
525 void f() { delete x; } // expected-error {{deleting incomplete class type}}
526 }
527
528 namespace DeleteIncompleteClassPointerError {
529 struct A; // expected-note {{forward declaration}}
530 void f(A *x) { 1+delete x; }
531 // expected-error@-1 {{invalid operands to binary expression}}
532 // cxx98-23-warning@-2 {{deleting pointer to incomplete type}}
533 // since-cxx26-error@-3 {{cannot delete pointer to incomplete type 'A'}}
534 }
535
536 namespace PR10504 {
537 struct A {
538 virtual void foo() = 0;
539 };
540 void f(A *x) { delete x; } // expected-warning {{delete called on 'PR10504::A' that is abstract but has non-virtual destructor}}
541 }
542
543 struct PlacementArg {};
544 inline void *operator new[](size_t, const PlacementArg &) throw () {
545 return 0;
546 }
547 inline void operator delete[](void *, const PlacementArg &) throw () {
548 }
549
550 namespace r150682 {
551
552 template <typename X>
553 struct S {
554 struct Inner {};
555 S() { new Inner[1]; }
556 };
557
558 struct T {
559 };
560
561 template<typename X>
562 void tfn() {
563 new (*(PlacementArg*)0) T[1]; // expected-warning 2 {{binding dereferenced null pointer to reference has undefined behavior}}
564 }
565
566 void fn() {
567 tfn<int>(); // expected-note {{in instantiation of function template specialization 'r150682::tfn<int>' requested here}}
568 }
569
570 }
571
572 namespace P12023 {
573 struct CopyCounter
574 {
575 CopyCounter();
576 CopyCounter(const CopyCounter&);
577 };
578
579 int main()
580 {
581 CopyCounter* f = new CopyCounter[10](CopyCounter()); // precxx20-error {{cannot have initialization arguments}}
582 return 0;
583 }
584 }
585
586 namespace PR12061 {
587 template <class C> struct scoped_array {
588 scoped_array(C* p = __null);
589 };
590 template <class Payload> struct Foo {
591 Foo() : a_(new scoped_array<int>[5]) { }
592 scoped_array< scoped_array<int> > a_;
593 };
594 class Bar {};
595 Foo<Bar> x;
596
597 template <class C> struct scoped_array2 {
598 scoped_array2(C* p = __null, C* q = __null);
599 };
600 template <class Payload> struct Foo2 {
601 Foo2() : a_(new scoped_array2<int>[5]) { }
602 scoped_array2< scoped_array2<int> > a_;
603 };
604 class Bar2 {};
605 Foo2<Bar2> x2;
606
607 class MessageLoop {
608 public:
609 explicit MessageLoop(int type = 0);
610 };
611 template <class CookieStoreTestTraits>
612 class CookieStoreTest {
613 protected:
614 CookieStoreTest() {
615 new MessageLoop;
616 }
617 };
618 struct CookieMonsterTestTraits {
619 };
620 class DeferredCookieTaskTest : public CookieStoreTest<CookieMonsterTestTraits>
621 {
622 DeferredCookieTaskTest() {}
623 };
624 }
625
626 class DeletingPlaceholder {
627 int* f() {
628 delete f; // expected-error {{reference to non-static member function must be called; did you mean to call it with no arguments?}}
629 return 0;
630 }
631 int* g(int, int) {
632 delete g; // expected-error {{reference to non-static member function must be called}}
633 return 0;
634 }
635 };
636
637 namespace PR18544 {
638 inline void *operator new(size_t); // expected-error {{'operator new' cannot be declared inside a namespace}}
639 }
640
641 // PR19968
642 inline void* operator new(); // expected-error {{'operator new' must have at least one parameter}}
643
644 namespace {
645 template <class C>
646 struct A {
647 void f() { this->::new; } // expected-error {{expected unqualified-id}}
648 void g() { this->::delete; } // expected-error {{expected unqualified-id}}
649 };
650 }
651
652 #if __cplusplus >= 201103L
653 template<typename ...T> int *dependent_array_size(T ...v) {
654 return new int[]{v...}; // expected-error {{cannot initialize}}
655 }
656 int *p0 = dependent_array_size();
657 int *p3 = dependent_array_size(1, 2, 3);
658 int *fail = dependent_array_size("hello"); // expected-note {{instantiation of}}
659 #endif
660
661 // FIXME: Our behavior here is incredibly inconsistent. GCC allows
662 // constant-folding in array bounds in new-expressions.
663 int (*const_fold)[12] = new int[3][&const_fold + 12 - &const_fold];
664 #if __cplusplus >= 201402L && !defined(NEW_INTERP)
665 // expected-error@-2 {{array size is not a constant expression}}
666 // expected-note@-3 {{cannot refer to element 12 of non-array}}
667 #elif __cplusplus < 201103L && !defined(NEW_INTERP)
668 // expected-error@-5 {{cannot allocate object of variably modified type}}
669 // expected-warning@-6 {{variable length arrays in C++ are a Clang extension}}
670 #endif
671 #ifdef NEW_INTERP
672 #if __cplusplus >= 201402L
673 // expected-error@-10 {{array size is not a constant expression}}
674 // expected-note@-11 {{cannot refer to element 12 of non-array}}
675 #elif __cplusplus >= 201103L
676 // expected-error@-13 {{only the first dimension of an allocated array may have dynamic size}}
677 // expected-note@-14 {{cannot refer to element 12 of non-array}}
678 #else
679 // expected-error@-16 {{only the first dimension of an allocated array may have dynamic size}}
680 // expected-note@-17 {{cannot refer to element 12 of non-array}}
681 #endif
682 #endif