|
| 1 | +// Without serialization: |
| 2 | +// RUN: %clang_cc1 -std=c++26 -ast-print %s | FileCheck %s |
| 3 | +// |
| 4 | +// With serialization: |
| 5 | +// RUN: %clang_cc1 -std=c++26 -emit-pch -o %t %s |
| 6 | +// RUN: %clang_cc1 -x c++ -std=c++26 -include-pch %t -ast-print /dev/null | FileCheck %s |
| 7 | + |
| 8 | +template <typename T, __SIZE_TYPE__ size> |
| 9 | +struct Array { |
| 10 | + T data[size]{}; |
| 11 | + constexpr const T* begin() const { return data; } |
| 12 | + constexpr const T* end() const { return data + size; } |
| 13 | +}; |
| 14 | + |
| 15 | +// CHECK: void foo(int); |
| 16 | +void foo(int); |
| 17 | + |
| 18 | +// CHECK: template <typename T> void test(T t) { |
| 19 | +template <typename T> |
| 20 | +void test(T t) { |
| 21 | + // Enumerating expansion statement. |
| 22 | + // |
| 23 | + // CHECK: template for (auto x : { 1, 2, 3 }) { |
| 24 | + // CHECK-NEXT: foo(x); |
| 25 | + // CHECK-NEXT: } |
| 26 | + template for (auto x : {1, 2, 3}) { |
| 27 | + foo(x); |
| 28 | + } |
| 29 | + |
| 30 | + // Iterating expansion statement. |
| 31 | + // |
| 32 | + // CHECK: static constexpr Array<int, 3> a; |
| 33 | + // CHECK-NEXT: template for (auto x : a) { |
| 34 | + // CHECK-NEXT: foo(x); |
| 35 | + // CHECK-NEXT: } |
| 36 | + static constexpr Array<int, 3> a; |
| 37 | + template for (auto x : a) { |
| 38 | + foo(x); |
| 39 | + } |
| 40 | + |
| 41 | + // Destructuring expansion statement. |
| 42 | + // |
| 43 | + // CHECK: int arr[3]{1, 2, 3}; |
| 44 | + // CHECK-NEXT: template for (auto x : arr) { |
| 45 | + // CHECK-NEXT: foo(x); |
| 46 | + // CHECK-NEXT: } |
| 47 | + int arr[3]{1, 2, 3}; |
| 48 | + template for (auto x : arr) { |
| 49 | + foo(x); |
| 50 | + } |
| 51 | + |
| 52 | + // Dependent expansion statement. |
| 53 | + // |
| 54 | + // CHECK: template for (auto x : t) { |
| 55 | + // CHECK-NEXT: foo(x); |
| 56 | + // CHECK-NEXT: } |
| 57 | + template for (auto x : t) { |
| 58 | + foo(x); |
| 59 | + } |
| 60 | +} |
| 61 | + |
| 62 | +// CHECK: template <typename T> void test2(T t) { |
| 63 | +template <typename T> |
| 64 | +void test2(T t) { |
| 65 | + // Enumerating expansion statement. |
| 66 | + // |
| 67 | + // CHECK: template for (int x : { 1, 2, 3 }) { |
| 68 | + // CHECK-NEXT: foo(x); |
| 69 | + // CHECK-NEXT: } |
| 70 | + template for (int x : {1, 2, 3}) { |
| 71 | + foo(x); |
| 72 | + } |
| 73 | + |
| 74 | + // Iterating expansion statement. |
| 75 | + // |
| 76 | + // CHECK: static constexpr Array<int, 3> a; |
| 77 | + // CHECK-NEXT: template for (int x : a) { |
| 78 | + // CHECK-NEXT: foo(x); |
| 79 | + // CHECK-NEXT: } |
| 80 | + static constexpr Array<int, 3> a; |
| 81 | + template for (int x : a) { |
| 82 | + foo(x); |
| 83 | + } |
| 84 | + |
| 85 | + // Destructuring expansion statement. |
| 86 | + // |
| 87 | + // CHECK: int arr[3]{1, 2, 3}; |
| 88 | + // CHECK-NEXT: template for (int x : arr) { |
| 89 | + // CHECK-NEXT: foo(x); |
| 90 | + // CHECK-NEXT: } |
| 91 | + int arr[3]{1, 2, 3}; |
| 92 | + template for (int x : arr) { |
| 93 | + foo(x); |
| 94 | + } |
| 95 | + |
| 96 | + // Dependent expansion statement. |
| 97 | + // |
| 98 | + // CHECK: template for (int x : t) { |
| 99 | + // CHECK-NEXT: foo(x); |
| 100 | + // CHECK-NEXT: } |
| 101 | + template for (int x : t) { |
| 102 | + foo(x); |
| 103 | + } |
| 104 | +} |
0 commit comments