1ecbf2f5fSBruno Ricci // Test without serialization:
2ecbf2f5fSBruno Ricci // RUN: %clang_cc1 -triple x86_64-unknown-unknown -ast-dump %s \
3ecbf2f5fSBruno Ricci // RUN: | FileCheck --strict-whitespace %s
4ecbf2f5fSBruno Ricci //
5ecbf2f5fSBruno Ricci // Test with serialization:
6ecbf2f5fSBruno Ricci // RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-pch -o %t %s
7ecbf2f5fSBruno Ricci // RUN: %clang_cc1 -x c++ -triple x86_64-unknown-unknown -include-pch %t -ast-dump-all /dev/null \
8ecbf2f5fSBruno Ricci // RUN: | sed -e "s/ <undeserialized declarations>//" -e "s/ imported//" \
9ecbf2f5fSBruno Ricci // RUN: | FileCheck --strict-whitespace %s
10765e1a44SStephen Kelly 
testArrayInitExpr()11765e1a44SStephen Kelly void testArrayInitExpr()
12765e1a44SStephen Kelly {
13765e1a44SStephen Kelly     int a[10];
14765e1a44SStephen Kelly     auto l = [a]{
15765e1a44SStephen Kelly     };
16765e1a44SStephen Kelly     // CHECK: |-ArrayInitLoopExpr 0x{{[^ ]*}} <col:15> 'int[10]'
17765e1a44SStephen Kelly     // CHECK: |     `-ArrayInitIndexExpr 0x{{[^ ]*}} <<invalid sloc>> 'unsigned long'
18765e1a44SStephen Kelly }
190fa7bf09SStephen Kelly 
200fa7bf09SStephen Kelly template<typename T, int Size>
210fa7bf09SStephen Kelly class array {
220fa7bf09SStephen Kelly   T data[Size];
230fa7bf09SStephen Kelly 
240fa7bf09SStephen Kelly   using array_T_size = T[Size];
250fa7bf09SStephen Kelly   // CHECK: `-DependentSizedArrayType 0x{{[^ ]*}} 'T[Size]' dependent   <col:25, col:30>
2640acc0adSDavid Blaikie   using const_array_T_size = const T[Size];
2740acc0adSDavid Blaikie   // CHECK: `-DependentSizedArrayType 0x{{[^ ]*}} 'const T[Size]' dependent   <col:37, col:42>
280fa7bf09SStephen Kelly };
29*09f8315bSSam McCall 
30*09f8315bSSam McCall struct V {};
31*09f8315bSSam McCall template <typename U, typename Idx, int N>
testDependentSubscript()32*09f8315bSSam McCall void testDependentSubscript() {
33*09f8315bSSam McCall   U* a;
34*09f8315bSSam McCall   U b[5];
35*09f8315bSSam McCall   Idx i{};
36*09f8315bSSam McCall   enum E { One = 1 };
37*09f8315bSSam McCall 
38*09f8315bSSam McCall   // Can types of subscript expressions can be determined?
39*09f8315bSSam McCall   // LHS is a type-dependent array, RHS is a known integer type.
40*09f8315bSSam McCall   a[1];
41*09f8315bSSam McCall   // CHECK: ArraySubscriptExpr {{.*}}line:[[@LINE-1]]{{.*}} 'U'
42*09f8315bSSam McCall   b[1];
43*09f8315bSSam McCall   // CHECK: ArraySubscriptExpr {{.*}}line:[[@LINE-1]]{{.*}} 'U'
44*09f8315bSSam McCall 
45*09f8315bSSam McCall   // Reverse case: RHS is a type-dependent array, LHS is an integer.
46*09f8315bSSam McCall   1[a];
47*09f8315bSSam McCall   // CHECK: ArraySubscriptExpr {{.*}}line:[[@LINE-1]]{{.*}} 'U'
48*09f8315bSSam McCall   1[b];
49*09f8315bSSam McCall   // CHECK: ArraySubscriptExpr {{.*}}line:[[@LINE-1]]{{.*}} 'U'
50*09f8315bSSam McCall 
51*09f8315bSSam McCall   // LHS is a type-dependent array, RHS is type-dependent.
52*09f8315bSSam McCall   a[i];
53*09f8315bSSam McCall   // CHECK: ArraySubscriptExpr {{.*}}line:[[@LINE-1]]{{.*}} '<dependent type>'
54*09f8315bSSam McCall   b[i];
55*09f8315bSSam McCall   // CHECK: ArraySubscriptExpr {{.*}}line:[[@LINE-1]]{{.*}} '<dependent type>'
56*09f8315bSSam McCall 
57*09f8315bSSam McCall   V *a2;
58*09f8315bSSam McCall   V b2[5];
59*09f8315bSSam McCall 
60*09f8315bSSam McCall   // LHS is a known array, RHS is type-dependent.
61*09f8315bSSam McCall   a2[i];
62*09f8315bSSam McCall   // CHECK: ArraySubscriptExpr {{.*}}line:[[@LINE-1]]{{.*}} '<dependent type>'
63*09f8315bSSam McCall   b2[i];
64*09f8315bSSam McCall   // CHECK: ArraySubscriptExpr {{.*}}line:[[@LINE-1]]{{.*}} '<dependent type>'
65*09f8315bSSam McCall 
66*09f8315bSSam McCall   // LHS is a known array, RHS is a type-dependent index.
67*09f8315bSSam McCall   // We know the element type is V, but insist on some dependent type.
68*09f8315bSSam McCall   a2[One];
69*09f8315bSSam McCall   // CHECK: ArraySubscriptExpr {{.*}}line:[[@LINE-1]]{{.*}} '<dependent type>'
70*09f8315bSSam McCall   b2[One];
71*09f8315bSSam McCall   // CHECK: ArraySubscriptExpr {{.*}}line:[[@LINE-1]]{{.*}} '<dependent type>'
72*09f8315bSSam McCall 
73*09f8315bSSam McCall   V b3[N];
74*09f8315bSSam McCall   // LHS is an array with dependent bounds but known elements.
75*09f8315bSSam McCall   // We insist on a dependent type.
76*09f8315bSSam McCall   b3[0];
77*09f8315bSSam McCall   // CHECK: ArraySubscriptExpr {{.*}}line:[[@LINE-1]]{{.*}} '<dependent type>'
78*09f8315bSSam McCall 
79*09f8315bSSam McCall   U b4[N];
80*09f8315bSSam McCall   // LHS is an array with dependent bounds and dependent elements.
81*09f8315bSSam McCall   b4[0];
82*09f8315bSSam McCall   // CHECK: ArraySubscriptExpr {{.*}}line:[[@LINE-1]]{{.*}} 'U'
83*09f8315bSSam McCall }
84