xref: /llvm-project/clang/test/AST/ast-dump-array.cpp (revision 09f8315bba391eac1dbdfbdc3fd654c0c0cbe3e7)
1 // Test without serialization:
2 // RUN: %clang_cc1 -triple x86_64-unknown-unknown -ast-dump %s \
3 // RUN: | FileCheck --strict-whitespace %s
4 //
5 // Test with serialization:
6 // RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-pch -o %t %s
7 // RUN: %clang_cc1 -x c++ -triple x86_64-unknown-unknown -include-pch %t -ast-dump-all /dev/null \
8 // RUN: | sed -e "s/ <undeserialized declarations>//" -e "s/ imported//" \
9 // RUN: | FileCheck --strict-whitespace %s
10 
testArrayInitExpr()11 void testArrayInitExpr()
12 {
13     int a[10];
14     auto l = [a]{
15     };
16     // CHECK: |-ArrayInitLoopExpr 0x{{[^ ]*}} <col:15> 'int[10]'
17     // CHECK: |     `-ArrayInitIndexExpr 0x{{[^ ]*}} <<invalid sloc>> 'unsigned long'
18 }
19 
20 template<typename T, int Size>
21 class array {
22   T data[Size];
23 
24   using array_T_size = T[Size];
25   // CHECK: `-DependentSizedArrayType 0x{{[^ ]*}} 'T[Size]' dependent   <col:25, col:30>
26   using const_array_T_size = const T[Size];
27   // CHECK: `-DependentSizedArrayType 0x{{[^ ]*}} 'const T[Size]' dependent   <col:37, col:42>
28 };
29 
30 struct V {};
31 template <typename U, typename Idx, int N>
testDependentSubscript()32 void testDependentSubscript() {
33   U* a;
34   U b[5];
35   Idx i{};
36   enum E { One = 1 };
37 
38   // Can types of subscript expressions can be determined?
39   // LHS is a type-dependent array, RHS is a known integer type.
40   a[1];
41   // CHECK: ArraySubscriptExpr {{.*}}line:[[@LINE-1]]{{.*}} 'U'
42   b[1];
43   // CHECK: ArraySubscriptExpr {{.*}}line:[[@LINE-1]]{{.*}} 'U'
44 
45   // Reverse case: RHS is a type-dependent array, LHS is an integer.
46   1[a];
47   // CHECK: ArraySubscriptExpr {{.*}}line:[[@LINE-1]]{{.*}} 'U'
48   1[b];
49   // CHECK: ArraySubscriptExpr {{.*}}line:[[@LINE-1]]{{.*}} 'U'
50 
51   // LHS is a type-dependent array, RHS is type-dependent.
52   a[i];
53   // CHECK: ArraySubscriptExpr {{.*}}line:[[@LINE-1]]{{.*}} '<dependent type>'
54   b[i];
55   // CHECK: ArraySubscriptExpr {{.*}}line:[[@LINE-1]]{{.*}} '<dependent type>'
56 
57   V *a2;
58   V b2[5];
59 
60   // LHS is a known array, RHS is type-dependent.
61   a2[i];
62   // CHECK: ArraySubscriptExpr {{.*}}line:[[@LINE-1]]{{.*}} '<dependent type>'
63   b2[i];
64   // CHECK: ArraySubscriptExpr {{.*}}line:[[@LINE-1]]{{.*}} '<dependent type>'
65 
66   // LHS is a known array, RHS is a type-dependent index.
67   // We know the element type is V, but insist on some dependent type.
68   a2[One];
69   // CHECK: ArraySubscriptExpr {{.*}}line:[[@LINE-1]]{{.*}} '<dependent type>'
70   b2[One];
71   // CHECK: ArraySubscriptExpr {{.*}}line:[[@LINE-1]]{{.*}} '<dependent type>'
72 
73   V b3[N];
74   // LHS is an array with dependent bounds but known elements.
75   // We insist on a dependent type.
76   b3[0];
77   // CHECK: ArraySubscriptExpr {{.*}}line:[[@LINE-1]]{{.*}} '<dependent type>'
78 
79   U b4[N];
80   // LHS is an array with dependent bounds and dependent elements.
81   b4[0];
82   // CHECK: ArraySubscriptExpr {{.*}}line:[[@LINE-1]]{{.*}} 'U'
83 }
84