[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / clang / test / SemaCXX / vla-construct.cpp
blob5a7d8334254221a32f9008b1090de83d95f91814
1 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fcxx-exceptions -fexceptions -O0 -verify %s
2 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fcxx-exceptions -fexceptions -pedantic-errors -DPE -O0 -verify %s
4 # ifndef PE
5 // expected-no-diagnostics
6 # endif
8 extern "C" int printf(const char*, ...);
10 static int N;
11 struct S {
12 S() __attribute__ ((nothrow)) { printf("%d: S()\n", ++N); }
13 ~S() __attribute__ ((nothrow)) { printf("%d: ~S()\n", N--); }
14 int n[17];
17 void print(int n, int a, int b, int c, int d) {
18 printf("n=%d\n,sizeof(S)=%d\nsizeof(array_t[0][0])=%d\nsizeof(array_t[0])=%d\nsizeof(array_t)=%d\n",
19 n, a, b, c, d);
20 if (n == 2) throw(n);
23 void test(int n) {
24 S array_t[n][n+1];
25 # ifdef PE
26 // expected-error@-2 {{variable length arrays are a C99 feature}} expected-note@-2 {{parameter}} expected-note@-3 {{here}}
27 // expected-error@-3 {{variable length arrays are a C99 feature}} expected-note@-3 {{parameter}} expected-note@-4 {{here}}
28 # endif
29 int sizeof_S = sizeof(S);
30 int sizeof_array_t_0_0 = sizeof(array_t[0][0]);
31 int sizeof_array_t_0 = sizeof(array_t[0]);
32 int sizeof_array_t = sizeof(array_t);
33 print(n, sizeof_S, sizeof_array_t_0_0, sizeof_array_t_0, sizeof_array_t);
36 int main()
38 try {
39 test(2);
40 } catch(int e) {
41 printf("exception %d\n", e);
43 try {
44 test(3);
45 } catch(int e) {
46 printf("exception %d", e);