xref: /aosp_15_r20/external/clang/test/SemaCXX/c99-variable-length-array-cxx11.cpp (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -Wvla-extension %s
2*67e74705SXin Li struct StillPOD {
3*67e74705SXin Li   StillPOD() = default;
4*67e74705SXin Li };
5*67e74705SXin Li 
6*67e74705SXin Li struct StillPOD2 {
7*67e74705SXin Li   StillPOD np;
8*67e74705SXin Li };
9*67e74705SXin Li 
10*67e74705SXin Li struct NonPOD {
NonPODNonPOD11*67e74705SXin Li   NonPOD(int) {}
12*67e74705SXin Li };
13*67e74705SXin Li 
14*67e74705SXin Li struct POD {
15*67e74705SXin Li   int x;
16*67e74705SXin Li   int y;
17*67e74705SXin Li };
18*67e74705SXin Li 
19*67e74705SXin Li // We allow VLAs of POD types, only.
vla(int N)20*67e74705SXin Li void vla(int N) {
21*67e74705SXin Li   int array1[N]; // expected-warning{{variable length arrays are a C99 feature}}
22*67e74705SXin Li   POD array2[N]; // expected-warning{{variable length arrays are a C99 feature}}
23*67e74705SXin Li   StillPOD array3[N]; // expected-warning{{variable length arrays are a C99 feature}}
24*67e74705SXin Li   StillPOD2 array4[N][3]; // expected-warning{{variable length arrays are a C99 feature}}
25*67e74705SXin Li   NonPOD array5[N]; // expected-error{{no matching constructor for initialization of 'NonPOD [N]'}}
26*67e74705SXin Li   // expected-warning@-1{{variable length arrays are a C99 feature}}
27*67e74705SXin Li   // expected-note@-16{{candidate constructor not viable}}
28*67e74705SXin Li   // expected-note@-18{{candidate constructor (the implicit copy constructor) not viable}}
29*67e74705SXin Li   // expected-note@-19{{candidate constructor (the implicit move constructor) not viable}}
30*67e74705SXin Li }
31